Skip to content

Commit 554a263

Browse files
meyeringJunio C Hamano
authored andcommitted
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>
1 parent d44c92d commit 554a263

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static void flush(void)
9696
if (output_fd >= 0)
9797
write_or_die(output_fd, input_buffer, input_offset);
9898
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);
100100
input_offset = 0;
101101
}
102102
}

0 commit comments

Comments
 (0)