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

Re: [PATCH] sequencer.c: fix overflow & segfault in parse_strategy_opts()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2023, 19:47 UTC
Message-ID
<xmqq5ybcxs1r.fsf@gitster.g>
In-Reply-To
<patch-1.1-f6a06e25cf3-20230307T182039Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
> There's a few things that use this for option parsing, but one way to
> trigger it is with a bad value to "-X <strategy-option>", e.g:
>
> 	git rebase -X"bad argument\""
Wow, that is nasty ;-).
Show 21 quoted lines
> diff --git a/sequencer.c b/sequencer.c
> index 3e4a1972897..79c615193b6 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2876,13 +2876,18 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
>  void parse_strategy_opts(struct replay_opts *opts, char *raw_opts)
>  {
>  	int i;
> +	int count;
>  	char *strategy_opts_string = raw_opts;
>  
>  	if (*strategy_opts_string == ' ')
>  		strategy_opts_string++;
>  
> -	opts->xopts_nr = split_cmdline(strategy_opts_string,
> -				       (const char ***)&opts->xopts);
> +	count = split_cmdline(strategy_opts_string,
> +			      (const char ***)&opts->xopts);
> +	if (count < 0)
> +		die(_("could not split '%s': '%s'"), strategy_opts_string,
> +			    split_cmdline_strerror(count));

This made me look at split_cmdline_strerror(). It is a table lookup into split_cmdline_errors[] in alias.c which looks like this:

    static const char *split_cmdline_errors[] = {
            N_("cmdline ends with \\"),
            N_("unclosed quote"),
            N_("too many arguments"),
    };

So the result is properly localized, but I suspect that the string after : should not be enclosed within a pair of single quotes.

	die(_("could not split '%s': %s", strategy_opts_string,
		split_cmdline_strerror(count)));
Other than that, nice find.
Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 2 of 4 in “sequencer.c: fix overflow & segfault in parse_strategy_opts()”
  1. sequencer.c: fix overflow & segfault in parse_strategy_opts()Ævar Arnfjörð Bjarmason, Mar 7, 2023
  2. Junio C HamanoMar 7, 2023
  3. Junio C HamanoMar 7, 2023
  4. Phillip WoodMar 8, 2023

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.