Skip to content

Commit dc4179f

Browse files
deskinspearce
authored andcommitted
maint: check return of split_cmdline to avoid bad config strings
As the testcase demonstrates, it's possible for split_cmdline to return -1 and deallocate any memory it's allocated, if the config string is missing an end quote. In both the cases below, which are the only calling sites, the return isn't checked, and using the pointer causes a pretty immediate segfault. Signed-off-by: Deskin Miller <deskinm@umich.edu> Acked-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent db87e39 commit dc4179f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

builtin-merge.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
442442

443443
buf = xstrdup(v);
444444
argc = split_cmdline(buf, &argv);
445+
if (argc < 0)
446+
die("Bad branch.%s.mergeoptions string", branch);
445447
argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
446448
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
447449
argc++;

git.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ static int handle_alias(int *argcp, const char ***argv)
162162
alias_string + 1, alias_command);
163163
}
164164
count = split_cmdline(alias_string, &new_argv);
165+
if (count < 0)
166+
die("Bad alias.%s string", alias_command);
165167
option_count = handle_options(&new_argv, &count, &envchanged);
166168
if (envchanged)
167169
die("alias '%s' changes environment variables\n"

t/t1300-repo-config.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,14 @@ test_expect_success 'symlinked configuration' '
741741
742742
'
743743

744+
test_expect_success 'check split_cmdline return' "
745+
git config alias.split-cmdline-fix 'echo \"' &&
746+
test_must_fail git split-cmdline-fix &&
747+
echo foo > foo &&
748+
git add foo &&
749+
git commit -m 'initial commit' &&
750+
git config branch.master.mergeoptions 'echo \"' &&
751+
test_must_fail git merge master
752+
"
753+
744754
test_done

0 commit comments

Comments
 (0)