git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Don't use memcpy when source and dest. buffers may overlap
@ 2006-12-11 18:06 Jim Meyering
  0 siblings, 0 replies; only message in thread
From: Jim Meyering @ 2006-12-11 18:06 UTC (permalink / raw)
  To: git

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>
---
 index-pack.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/index-pack.c b/index-pack.c
index 8331d99..6d6c92b 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -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;
 	}
 }
--

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2006-12-11 18:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-11 18:06 [PATCH] Don't use memcpy when source and dest. buffers may overlap Jim Meyering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).