{"thread":{"id":"43759","subject":"[PATCH] Don't use memcpy when source and dest. buffers may overlap","startedAt":"2006-12-11T18:06:34Z","lastAt":"2006-12-11T18:06:34Z","messageCount":1,"participants":["Jim Meyering"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"298173","messageId":"87slfm489h.fsf@rho.meyering.net","threadId":"43759","inReplyTo":null,"subject":"[PATCH] Don't use memcpy when source and dest. buffers may overlap","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2006-12-11T18:06:34Z","receivedAt":"2006-12-11T18:06:34Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"git-index-pack can call memcpy with overlapping source and destination\nbuffers.  The patch below makes it use memmove instead.\n\nIf you want to demonstrate a failure, add the following two lines\n\n+               if (input_offset < input_len)\n+                 abort ();\n\nbefore the existing memcpy call (shown in the patch below),\nand then run this:\n\n  (cd t; sh ./t5500-fetch-pack.sh)\n\n\nSigned-off-by: Jim Meyering <jim@meyering.net>\n---\n index-pack.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/index-pack.c b/index-pack.c\nindex 8331d99..6d6c92b 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -96,7 +96,7 @@ static void flush(void)\n \t\tif (output_fd >= 0)\n \t\t\twrite_or_die(output_fd, input_buffer, input_offset);\n \t\tSHA1_Update(&input_ctx, input_buffer, input_offset);\n-\t\tmemcpy(input_buffer, input_buffer + input_offset, input_len);\n+\t\tmemmove(input_buffer, input_buffer + input_offset, input_len);\n \t\tinput_offset = 0;\n \t}\n }\n--\n"}]}