Fix overflow of sum2 buffer for sha1 rolling checksums.
authorWayne Davison <wayne@opencoder.net>
Sat, 22 Apr 2023 15:49:48 +0000 (08:49 -0700)
committerWayne Davison <wayne@opencoder.net>
Sat, 22 Apr 2023 15:49:50 +0000 (08:49 -0700)
Fixed #353.

checksum.c
generator.c
match.c

index c6007f36895bba698667377b1f787ea1d1444a95..cd741d1ba7342a26cd1dca1d6844857fddf12958 100644 (file)
@@ -300,6 +300,7 @@ uint32 get_checksum1(char *buf1, int32 len)
 }
 #endif
 
+/* The "sum" buffer must be at least MAX_DIGEST_LEN bytes! */
 void get_checksum2(char *buf, int32 len, char *sum)
 {
 #ifdef USE_OPENSSL
index 21c4a595a1cbc148516b138a62384bec1d961915..557769e659102969a474ddc27f42084677d3770b 100644 (file)
@@ -783,7 +783,7 @@ static int generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy)
        for (i = 0; i < sum.count; i++) {
                int32 n1 = (int32)MIN(len, (OFF_T)sum.blength);
                char *map = map_ptr(mapbuf, offset, n1);
-               char sum2[SUM_LENGTH];
+               char sum2[MAX_DIGEST_LEN];
                uint32 sum1;
 
                len -= n1;
diff --git a/match.c b/match.c
index 6243994caa52799cd49d19bf0b5b6a305e7f04d3..192b154a2dd3a28ca1ef6d75fbcafd5a2c7c84a9 100644 (file)
--- a/match.c
+++ b/match.c
@@ -142,7 +142,7 @@ static void hash_search(int f,struct sum_struct *s,
 {
        OFF_T offset, aligned_offset, end;
        int32 k, want_i, aligned_i, backup;
-       char sum2[SUM_LENGTH];
+       char sum2[MAX_DIGEST_LEN];
        uint32 s1, s2, sum;
        int more;
        schar *map;