@matheusbsbs / matheus-bagliano / commits / 554a2636f7
Fork 0

Don't use memcpy when source and dest. buffers may overlap

git-index-pack can call memcpy with overlapping source and destination buffers. The patch below makes it use memmove instead. If you want to demonstrate a failure, add the following two lines + if (input_offset < input_len) + abort (); before the existing memcpy call (shown in the patch below), and then run this: (cd t; sh ./t5500-fetch-pack.sh) Signed-off-by: Jim Meyering <jim@meyering.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jim Meyering committed Dec 11, 2006 at 19:06 UTC 554a2636f7c5125a83bb07194632445467d46c83
1 file changed +1 -1
index-pack.c
+1 -1
@@ -96,7 +96,7 @@ static void flush(void)
96 if (output_fd >= 0)
97 write_or_die(output_fd, input_buffer, input_offset);
98 SHA1_Update(&input_ctx, input_buffer, input_offset);
99 - memcpy(input_buffer, input_buffer + input_offset, input_len);
99 + memmove(input_buffer, input_buffer + input_offset, input_len);
100 input_offset = 0;
101 }
102 }