@matheusbsbs / matheus-bagliano / commits / 27d5438d9f
Fork 0

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 8, 2009 at 05:06 UTC 27d5438d9f4eb2cefc2a989c68f9b42b529b2a12
1 file changed +4 -4
alias.c
+4 -4
@@ -38,10 +38,7 @@ int split_cmdline(char *cmdline, const char ***argv)
38 while (cmdline[++src]
39 && isspace(cmdline[src]))
40 ; /* skip */
41 - if (count >= size) {
42 - size += 16;
43 - *argv = xrealloc(*argv, sizeof(char*) * size);
44 - }
41 + ALLOC_GROW(*argv, count+1, size);
42 (*argv)[count++] = cmdline + dst;
43 } else if (!quoted && (c == '\'' || c == '"')) {
44 quoted = c;
@@ -72,6 +69,9 @@ int split_cmdline(char *cmdline, const char ***argv)
69 return error("unclosed quote");
70 }
71
72 + ALLOC_GROW(*argv, count+1, size);
73 + (*argv)[count] = NULL;
74 +
75 return count;
76 }
77