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

Re: [PATCH 3/5] config: add BUG() statement instead of possible segfault

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 27, 2022, 16:17 UTC
Message-ID
<220927.86wn9oyejm.gmgdl@evledraar.gmail.com>
In-Reply-To
<f277a7a429db8f54fa06dd1965d62ec491e6d84b.1664287711.git.gitgitgadget@gmail.com>
On Tue, Sep 27 2022, Derrick Stolee via GitGitGadget wrote:
Show 34 quoted lines
> From: Derrick Stolee <derrickstolee@github.com>
>
> The git_die_config() method calls git_config_get_value_multi() but
> immediately navigates to its first value without checking if the result
> is NULL or empty. Callers should only call git_die_config() if there is
> at least one value for the given 'key', but such a mistaken use might
> slip through. It would be better to show a BUG() statement than a
> possible segfault.
>
> Signed-off-by: Derrick Stolee <derrickstolee@github.com>
> ---
>  config.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/config.c b/config.c
> index bf89afbdab0..0c41606c7d4 100644
> --- a/config.c
> +++ b/config.c
> @@ -2833,8 +2833,13 @@ void git_die_config(const char *key, const char *err, ...)
>  		va_end(params);
>  	}
>  	values = git_config_get_value_multi(key);
> -	kv_info = values->items[values->nr - 1].util;
> -	git_die_config_linenr(key, kv_info->filename, kv_info->linenr);
> +
> +	if (values && values->nr) {
> +		kv_info = values->items[values->nr - 1].util;
> +		git_die_config_linenr(key, kv_info->filename, kv_info->linenr);
> +	} else {
> +		BUG("expected a non-empty list of values");
> +	}
>  }
>  
>  /*

AFAIKT the intent of the current code on "master" is that this will only get called if the likes of git_configset_get_string() returns < 0, not if it returns > 0.

So isn't the combination of your 1/5 and this 3/5 now conflating these two conditions? See e.g. repo_config_get_string_tmp() and when it would call git_die_config().

I.e. isn't the whole point of git_die_config() to print an error message about a configuration *value* that we've parsed out of the config?

If e.g. the key itself is bad we'll get a -1, but in this case it seems we would have a BUG(), but it's not that we "expected a non-empty list of values", but that the state of the world changed between our previous configset invocation, no?

Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee
Message 5 of 21 in “[RFC] config API: return empty list, not NULL”
  1. 0/5 [RFC] config API: return empty list, not NULLDerrick Stolee via GitGitGadget, Sep 27, 2022
  2. 1/5 config: relax requirements on multi-value returnDerrick Stolee via GitGitGadget, Sep 27, 2022
  3. Junio C HamanoSep 27, 2022
  4. 3/5 config: add BUG() statement instead of possible segfaultDerrick Stolee via GitGitGadget, Sep 27, 2022
  5. Ævar Arnfjörð BjarmasonSep 27, 2022
  6. Derrick StoleeSep 27, 2022
  7. Ævar Arnfjörð BjarmasonSep 27, 2022
  8. 4/5 config: return an empty list, not NULLDerrick Stolee via GitGitGadget, Sep 27, 2022
  9. Ævar Arnfjörð BjarmasonSep 27, 2022
  10. Derrick StoleeSep 27, 2022
  11. Ævar Arnfjörð BjarmasonSep 27, 2022
  12. Derrick StoleeSep 28, 2022
  13. Ævar Arnfjörð BjarmasonSep 28, 2022
  14. Derrick StoleeSep 28, 2022
  15. Ævar Arnfjörð BjarmasonSep 28, 2022
  16. 2/5 *: relax git_configset_get_value_multi resultDerrick Stolee via GitGitGadget, Sep 27, 2022
  17. Taylor BlauSep 28, 2022
  18. 5/5 *: expect a non-NULL list of config valuesDerrick Stolee via GitGitGadget, Sep 27, 2022
  19. Junio C HamanoSep 28, 2022
  20. Derrick StoleeSep 28, 2022
  21. Ævar Arnfjörð BjarmasonSep 28, 2022

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.