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

Re: [PATCH v4 3/3] upload-archive: use start_command instead of fork

From
Jeff King <peff@peff.net>
Date
Nov 15, 2011, 19:18 UTC
Message-ID
<20111115191832.GA16030@sigill.intra.peff.net>
In-Reply-To
<7vobwdus7w.fsf@alter.siamese.dyndns.org>
On Tue, Nov 15, 2011 at 10:59:47AM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > Junio, this bug is in 1.7.8-rc*. Do you want the one-liner fix for the
> > release, or the nicer fix?
> 
> Let's just do "static" for now, if we know the array is large enough.
OK, here it is.

I think it's correct, but I couldn't reproduce the valgrind failure here. Thomas, can you double check that this also solves your problem?

-Peff
-- >8 --
Subject: [PATCH] upload-archive: don't return pointers to stack buffer

The prepare_argv function uses an internal stack-allocated buffer to create the argv array that will be used to run git-archive. Prior to c09cd77e, this was OK, as the function passed the argv array to write_archive itself, and the stack buffer was valid during its use.

Since c09cd77e, however, the function returns an argv array with pointers pointing into the stack buffer. The calling function then passes the result to start_command, which tries to execve using pointers to a now-invalid buffer.

Fix it by making the buffer static, which is a quick and simple fix, and works because we only run this function once per process.

Credit for finding the bug and most of the analysis goes to Thomas Rast.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/upload-archive.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index c57e8bd..f47c0f0 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -22,7 +22,8 @@
 static void prepare_argv(const char **sent_argv, const char **argv)
 {
 	const char *arg_cmd = "argument ";
-	char *p, buf[4096];
+	char *p;
+	static char buf[4096];
 	int sent_argc;
 	int len;
 
-- 
1.7.7.3.8.g38efa
Previous: Junio C HamanoNext: Jeff King
Message 13 of 17 in “port upload-archive to Windows”
  1. 0/3 port upload-archive to WindowsErik Faye-Lund, Oct 24, 2011
  2. 1/3 mingw: move poll out of sys-folderErik Faye-Lund, Oct 24, 2011
  3. 2/3 compat/win32/poll.c: upgrade from upstreamErik Faye-Lund, Oct 24, 2011
  4. 3/3 upload-archive: use start_command instead of forkErik Faye-Lund, Oct 24, 2011
  5. Jeff KingOct 24, 2011
  6. Thomas RastNov 15, 2011
  7. Jeff KingNov 15, 2011
  8. Thomas RastNov 15, 2011
  9. Jeff KingNov 15, 2011
  10. Erik Faye-LundNov 15, 2011
  11. Jeff KingNov 15, 2011
  12. Junio C HamanoNov 15, 2011
  13. Jeff KingNov 15, 2011
  14. 1/2 upload-archive: drop extra argument to prepare_argvJeff King, Nov 15, 2011
  15. upload-archive: use argv_array for sent parametersJeff King, Nov 15, 2011
  16. Jeff KingNov 15, 2011
  17. Andreas SchwabNov 15, 2011

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.