Skip to content

Commit

Permalink
Don't use memcpy when source and dest. buffers may overlap
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
meyering authored and Junio C Hamano committed Dec 11, 2006
1 parent d44c92d commit 554a263
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void flush(void)
if (output_fd >= 0)
write_or_die(output_fd, input_buffer, input_offset);
SHA1_Update(&input_ctx, input_buffer, input_offset);
memcpy(input_buffer, input_buffer + input_offset, input_len);
memmove(input_buffer, input_buffer + input_offset, input_len);
input_offset = 0;
}
}
Expand Down

0 comments on commit 554a263

Please sign in to comment.