diff --git a/checksum.c b/checksum.c index 66e80896..2b2277c2 100644 --- a/checksum.c +++ b/checksum.c @@ -373,25 +373,27 @@ void get_checksum2(char *buf, int32 len, char *sum) len1 = len; } - memcpy(buf1, buf, len); - if (checksum_seed) { - SIVAL(buf1,len,checksum_seed); - len += 4; - } + if (buf1) { + memcpy(buf1, buf, len); + if (checksum_seed) { + SIVAL(buf1,len,checksum_seed); + len += 4; + } - for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) - mdfour_update(&m, (uchar *)(buf1+i), CSUM_CHUNK); + for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) + mdfour_update(&m, (uchar *)(buf1+i), CSUM_CHUNK); - /* - * Prior to version 27 an incorrect MD4 checksum was computed - * by failing to call mdfour_tail() for block sizes that - * are multiples of 64. This is fixed by calling mdfour_update() - * even when there are no more bytes. - */ - if (len - i > 0 || xfer_sum_nni->num > CSUM_MD4_BUSTED) - mdfour_update(&m, (uchar *)(buf1+i), len-i); + /* + * Prior to version 27 an incorrect MD4 checksum was computed + * by failing to call mdfour_tail() for block sizes that + * are multiples of 64. This is fixed by calling mdfour_update() + * even when there are no more bytes. + */ + if (len - i > 0 || xfer_sum_nni->num > CSUM_MD4_BUSTED) + mdfour_update(&m, (uchar *)(buf1+i), len-i); - mdfour_result(&m, (uchar *)sum); + mdfour_result(&m, (uchar *)sum); + } break; } default: /* paranoia to prevent missing case values */