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

[PATCH] fetch-pack: Avoid memcpy() with src==dst

From
Thomas Rast <trast@student.ethz.ch>
Date
Dec 6, 2008, 20:50 UTC
Message-ID
<1228596609-12720-1-git-send-email-trast@student.ethz.ch>

memcpy() may only be used for disjoint memory areas, but when invoked from cmd_fetch_pack(), we have my_args == &args. (The argument cannot be removed entirely because transport.c invokes with its own variable.)

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Found this while valgrinding too much.
 builtin-fetch-pack.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 372bfa2..67fb80e 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -780,7 +780,8 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
 	struct ref *ref_cpy;
 
 	fetch_pack_setup();
-	memcpy(&args, my_args, sizeof(args));
+	if (&args != my_args)
+		memcpy(&args, my_args, sizeof(args));
 	if (args.depth > 0) {
 		if (stat(git_path("shallow"), &st))
 			st.st_mtime = 0;
-- 
tg: (7f705dc..) t/fp-memcpy-fix (depends on: origin/master)
Next: Junio C Hamano
Message 1 of 2 in “fetch-pack: Avoid memcpy() with src==dst”
  1. fetch-pack: Avoid memcpy() with src==dstThomas Rast, Dec 6, 2008
  2. Junio C HamanoDec 8, 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.