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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux