Skip to content

Commit 27d5438

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2c5b011 commit 27d5438

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

alias.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ int split_cmdline(char *cmdline, const char ***argv)
3838
while (cmdline[++src]
3939
&& isspace(cmdline[src]))
4040
; /* skip */
41-
if (count >= size) {
42-
size += 16;
43-
*argv = xrealloc(*argv, sizeof(char*) * size);
44-
}
41+
ALLOC_GROW(*argv, count+1, size);
4542
(*argv)[count++] = cmdline + dst;
4643
} else if (!quoted && (c == '\'' || c == '"')) {
4744
quoted = c;
@@ -72,6 +69,9 @@ int split_cmdline(char *cmdline, const char ***argv)
7269
return error("unclosed quote");
7370
}
7471

72+
ALLOC_GROW(*argv, count+1, size);
73+
(*argv)[count] = NULL;
74+
7575
return count;
7676
}
7777

0 commit comments

Comments
 (0)