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

[PATCH] Fix invocation of external git commands with arguments with spaces.

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Oct 10, 2007, 07:00 UTC
Message-ID
<470C787C.6090900@viscovery.net>
In-Reply-To
<470C6E58.3080208@viscovery.net>

If an external git command (not a shell script) was invoked with arguments that contain spaces, these arguments would be split into separate arguments. They must be quoted. This also affected installations where $prefix contained a space, as in "C:\Program Files\GIT". Both errors can be triggered by invoking

     git hash-object "a b"

where "a b" is an existing file. --- Johannes Sixt schrieb:

> BTW, I think the fix is incomplete anyway: We quote only argv[0], but 
> actually all of argv should be quoted. Will test.
Here is the proper fix.
Yes, this leaks memory on the error path. We can clean that up later...
-- Hannes
  compat/mingw.c |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 8bb0dba..2554f19 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -405,7 +405,12 @@ void mingw_execve()
  {
  	/* check if git_command is a shell script */
  	if (!try_shell_exec(cmd, argv, env)) {
-		int ret = spawnve(_P_WAIT, cmd, argv, env);
+		const char **qargv;
+		int n;
+		for (n = 0; argv[n];) n++;
+		qargv = xmalloc((n+1)*sizeof(char*));
+		quote_argv(qargv, argv);
+		int ret = spawnve(_P_WAIT, cmd, qargv, env);
  		if (ret != -1)
  			exit(ret);
  	}
-- 
1.5.3.717.g01fc-dirty
Previous: Johannes Sixt
Message 17 of 17 in “Merge problems with git-mingw”
  1. Peter KarlssonOct 8, 2007
  2. Lars HjemliOct 8, 2007
  3. Peter KarlssonOct 8, 2007
  4. Lars HjemliOct 8, 2007
  5. Peter KarlssonOct 8, 2007
  6. Lars HjemliOct 8, 2007
  7. Johannes SixtOct 9, 2007
  8. Peter KarlssonOct 9, 2007
  9. Johannes SixtOct 9, 2007
  10. Peter KarlssonOct 9, 2007
  11. Johannes SixtOct 9, 2007
  12. Steffen ProhaskaOct 9, 2007
  13. Johannes SixtOct 9, 2007
  14. Linus TorvaldsOct 9, 2007
  15. exec_git_cmd: fix executing commands if path contains spacesSteffen Prohaska, Oct 9, 2007
  16. Johannes SixtOct 10, 2007
  17. Fix invocation of external git commands with arguments with spaces.Johannes Sixt, Oct 10, 2007

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.