@matheusbsbs / matheus-bagliano / commits / dc4179f9a7
Fork 0

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>

Deskin Miller committed Sep 22, 2008 at 11:06 UTC dc4179f9a76473176eb473f6f568b0006c823fba
3 files changed +14
builtin-merge.c
+2
@@ -442,6 +442,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
442
443 buf = xstrdup(v);
444 argc = split_cmdline(buf, &argv);
445 + if (argc < 0)
446 + die("Bad branch.%s.mergeoptions string", branch);
447 argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
448 memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
449 argc++;
git.c
+2
@@ -162,6 +162,8 @@ static int handle_alias(int *argcp, const char ***argv)
162 alias_string + 1, alias_command);
163 }
164 count = split_cmdline(alias_string, &new_argv);
165 + if (count < 0)
166 + die("Bad alias.%s string", alias_command);
167 option_count = handle_options(&new_argv, &count, &envchanged);
168 if (envchanged)
169 die("alias '%s' changes environment variables\n"
t/t1300-repo-config.sh
+10
@@ -741,4 +741,14 @@ test_expect_success 'symlinked configuration' '
741
742 '
743
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 +
754 test_done