git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 5/5] fix overlapping memcpy in normalize_absolute_path

From
Jeff King <peff@peff.net>
Date
Oct 22, 2008, 20:32 UTC
Message-ID
<20081022203222.GE4547@coredump.intra.peff.net>
In-Reply-To
<20081022202810.GA4439@coredump.intra.peff.net>

The comments for normalize_absolute_path explicitly claim that the source and destination buffers may be the same (though they may not otherwise overlap). Thus the call to memcpy may involve copying overlapping data, and memmove should be used instead.

This fixes a valgrind error in t1504.
Signed-off-by: Jeff King <peff@peff.net>
---
An alternative fix, since we declare that only true equality is OK,
would be to keep the memcpy and explicitly check for "comp_start ==
dst". That might have a performance benefit if memcpy is faster than
memmove, but I don't know that normalize_absolute_path is in any
critical paths.
 path.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/path.c b/path.c
index 76e8872..c1cb54b 100644
--- a/path.c
+++ b/path.c
@@ -348,7 +348,7 @@ int normalize_absolute_path(char *buf, const char *path)
 			goto next;
 		}
 
-		memcpy(dst, comp_start, comp_len);
+		memmove(dst, comp_start, comp_len);
 		dst += comp_len;
 	next:
 		comp_start = comp_end;
-- 
1.6.0.2.825.g6d19d
Previous: Nicolas Pitre
Message 13 of 13 in “valgrind in test scripts”
  1. 0/5 valgrind in test scriptsJeff King, Oct 22, 2008
  2. 1/5 add valgrind support in test scriptsJeff King, Oct 22, 2008
  3. Johannes SchindelinOct 22, 2008
  4. Junio C HamanoOct 23, 2008
  5. Jeff KingOct 23, 2008
  6. Jeff KingOct 23, 2008
  7. 2/5 valgrind: ignore ldso errorsJeff King, Oct 22, 2008
  8. 3/5 correct cache_entry allocationJeff King, Oct 22, 2008
  9. 4/5 pack-objects: avoid reading uninitalized dataJeff King, Oct 22, 2008
  10. Nicolas PitreOct 23, 2008
  11. Jeff KingOct 23, 2008
  12. Nicolas PitreOct 23, 2008
  13. 5/5 fix overlapping memcpy in normalize_absolute_pathJeff King, Oct 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.