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

Re: git config set --file, key-value pair without '= value', gives Segmentation fault

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 31, 2024, 22:47 UTC
Message-ID
<xmqq5xslyyaf.fsf@gitster.g>
In-Reply-To
<ZqqucpNgqSgZDPtA@nand.local>
Show 18 quoted lines
> So I think that the behavior dates back to c90702a1f6 (config: plumb
> --fixed-value into config API, 2020-11-25). I think that the fix looks
> something like:
>
> --- 8< ---
> diff --git a/config.c b/config.c
> index 6421894614..05f369ec0d 100644
> --- a/config.c
> +++ b/config.c
> @@ -2914,7 +2914,7 @@ static int matches(const char *key, const char *value,
>  {
>  	if (strcmp(key, store->key))
>  		return 0; /* not ours */
> -	if (store->fixed_value)
> +	if (store->fixed_value && value)
>  		return !strcmp(store->fixed_value, value);
>  	if (!store->value_pattern)
>  		return 1; /* always matches */

Hmph. fixed_value is about the string given on the command line being not a pattern. And value that is NULL is the valueless "true" in this case.

I would have actually expected the fix that follow your analysis (by the way, I found it really well done) would say something more like

	if (strcmp(key, store->key))
		return 0; /* not ours */
+	if (!value)
+		value = "true";
	if (store->fixed_value)
		return !strcmp(store->fixed_value, value);

but I am not sure exactly how we want to handle synonymous Boolean values here. Regardless of how "true" value is spelled in the configuration file, e.g.

        [section]               [section]
                key                     key = true

I wonder if "git config set --value=yes [--fixed-value] section.key false" should replace either of them to false.

It would especially true if the command is invoked with --type=bool but it seems that the --type option does not participate in the matching with the current value.

> I'd like to hear from Stolee (CC'd), who is the author of c90702a1f6
> before submitting this as a standalone patch.
Previous: Taylor BlauNext: Taylor Blau
Message 3 of 6 in “git config set --file, key-value pair without '= value', gives Segmentation fault”
  1. Han JiangJul 31, 2024
  2. Taylor BlauJul 31, 2024
  3. Junio C HamanoJul 31, 2024
  4. Taylor BlauJul 31, 2024
  5. Han JiangJul 31, 2024
  6. Junio C HamanoAug 1, 2024

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.