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

Re: Two problems on alias of git

From
Jeff King <peff@peff.net>
Date
May 8, 2009, 09:06 UTC
Message-ID
<20090508090614.GB29737@coredump.intra.peff.net>
In-Reply-To
<op.utgiv92f6f2obg@i220-99-253-139.s27.a098.ap.plala.or.jp>
On Tue, May 05, 2009 at 09:42:04PM +0900, Kana Natsuno wrote:
> The first one is that git crashes with the following situation.
> Without GIT_TRACE, everthing works well.  But with GIT_TRACE=1,
> git crashes every time.

I wasn't able to reproduce on Linux, but valgrind found it. The patch below should fix it.

-- >8 --
Subject: [PATCH] fix GIT_TRACE segfault with shell-quoted aliases

The alias argv comes from the split_cmdline function, which splits the config text for the alias into an array of strings. It returns the number of elements in the array, but does not actually put a NULL at the end of the array. Later, the trace function tries to print this argv and assumes that it has the trailing NULL.

The split_cmdline function is probably at fault, since argv lists almost always end with a NULL signal. This patch adds one, in addition to the returned count; this doesn't hurt the other callers at all, since they were presumably using the count already (and will never look at the NULL).

While we're there and using ALLOC_GROW, let's clean up the other manual grow.

Signed-off-by: Jeff King <peff@peff.net>
---
 alias.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/alias.c b/alias.c
index e687fe5..372b7d8 100644
--- a/alias.c
+++ b/alias.c
@@ -38,10 +38,7 @@ int split_cmdline(char *cmdline, const char ***argv)
 			while (cmdline[++src]
 					&& isspace(cmdline[src]))
 				; /* skip */
-			if (count >= size) {
-				size += 16;
-				*argv = xrealloc(*argv, sizeof(char *) * size);
-			}
+			ALLOC_GROW(*argv, count+1, size);
 			(*argv)[count++] = cmdline + dst;
 		} else if (!quoted && (c == '\'' || c == '"')) {
 			quoted = c;
@@ -72,6 +69,9 @@ int split_cmdline(char *cmdline, const char ***argv)
 		return error("unclosed quote");
 	}
 
+	ALLOC_GROW(*argv, count+1, size);
+	(*argv)[count] = NULL;
+
 	return count;
 }
 
-- 
1.6.3.203.g7c7de.dirty
Previous: Jakub Narebski
Message 7 of 7 in “Two problems on alias of git”
  1. Kana NatsunoMay 5, 2009
  2. Jakub NarebskiMay 5, 2009
  3. Kana NatsunoMay 5, 2009
  4. Jakub NarebskiMay 5, 2009
  5. Kana NatsunoMay 5, 2009
  6. Jakub NarebskiMay 5, 2009
  7. Jeff KingMay 8, 2009

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.