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

[BUG] [PATCH]: run-command.c

From
DRDuncan Roe <duncan_roe@acslink.net.au>
Date
Oct 21, 2016, 05:50 UTC
Message-ID
<20161021055013.GA31554@dimstar.local.net>

prepare_shell_cmd() executes /bin/sh with superfluous arguments on all but single-word shell commands.

For example, if .git/config has this alias (the sleep is to leave time to examine output from ps, &c.):

[alias]
	tryme = "!echo $PWD;sleep 600"
running "git tryme" in one console and checking what it does in another
--- 1st xterm

16:42:12$ git tryme /usr/src/git/.git echo $PWD;sleep 600: line 1: 2602 Terminated sleep 600 16:43:15$

--- 2nd xterm
16:42:06$ ps axf|grep -A2 trym[e]
 2599 pts/4    S+     0:00      \_ git tryme
 2601 pts/4    S+     0:00          \_ /bin/sh -c echo $PWD;sleep 600 echo $PWD;sleep 600
 2602 pts/4    S+     0:00              \_ sleep 600
16:42:45$ cat /proc/2601/cmdline | xargs -0 -n1 echo
/bin/sh
-c
echo $PWD;sleep 600
echo $PWD;sleep 600
16:43:04$ kill 2602
16:43:15$
---

There is an extra "-c" argument. This is caused by a missing "else", fixed by the appended patch,

Cheers ... Duncan.
----------8<-------------------
--- a/run-command.c
+++ b/run-command.c
@@ -182,8 +182,8 @@ static const char **prepare_shell_cmd(struct argv_array *out, const char **argv)
 		else
 			argv_array_pushf(out, "%s \"$@\"", argv[0]);
 	}
-
-	argv_array_pushv(out, argv);
+	else
+		argv_array_pushv(out, argv);
 	return out->argv;
 }
Next: Jeff King
Message 1 of 4 in “: run-command.c”
  1. Duncan RoeOct 21, 2016
  2. Jeff KingOct 21, 2016
  3. Duncan RoeOct 21, 2016
  4. Junio C HamanoOct 21, 2016

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.