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

Re: [PATCH] maint: check return of split_cmdline to avoid bad config strings

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Sep 24, 2008, 09:28 UTC
Message-ID
<20080924092847.GD23137@genesis.frugalware.org>
In-Reply-To
<20080924061028.GA2792@riemann.deskinm.fdns.net>
On Wed, Sep 24, 2008 at 02:10:28AM -0400, Deskin Miller <deskinm@umich.edu> wrote:
> As the testcase demonstrates, it's possible to have split_cmdline return -1 and
> deallocate any memory it's allocated, if the config string is missing an end
> quote.  In both the cases below, the return isn't checked, causing a pretty
> immediate segfault.
I think this could go to the commit message.
Show 13 quoted lines
> diff --git a/builtin-merge.c b/builtin-merge.c
> index b280444..dcaf368 100644
> --- a/builtin-merge.c
> +++ b/builtin-merge.c
> @@ -442,6 +442,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
>  
>  		buf = xstrdup(v);
>  		argc = split_cmdline(buf, &argv);
> +		if (argc < 0)
> +			die("Bad branch.%s.mergeoptions string", branch);
>  		argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
>  		memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
>  		argc++;
ACK.
Show 17 quoted lines
> diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
> index 64567fb..3794d23 100755
> --- a/t/t1300-repo-config.sh
> +++ b/t/t1300-repo-config.sh
> @@ -741,4 +741,14 @@ test_expect_success 'symlinked configuration' '
>  
>  '
>  
> +test_expect_success 'check split_cmdline return' "
> +	git config alias.split-cmdline-fix 'echo \"' &&
> +	git split-cmdline-fix || test \$? = 128 &&
> +	echo foo > foo &&
> +	git add foo &&
> +	git commit -m 'initial commit' &&
> +	git config branch.master.mergeoptions 'echo \"' &&
> +	git merge master || test \$? = 128
> +	"
Why don't you use test_must_fail here?
Previous: Deskin MillerNext: Deskin Miller
Message 2 of 4 in “maint: check return of split_cmdline to avoid bad config strings”
  1. maint: check return of split_cmdline to avoid bad config stringsDeskin Miller, Sep 24, 2008
  2. Miklos VajnaSep 24, 2008
  3. Deskin MillerSep 24, 2008
  4. Miklos VajnaSep 24, 2008

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.