diff options
author | Jeff King <peff@peff.net> | 2023-12-07 08:11:14 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-12-09 00:24:39 +0100 |
commit | ba176db511b3438738a4aeb98e574310e697ff5f (patch) | |
tree | 647a878be2c8d0f0d48a8f74f9f9fcfc051fecd1 /config.c | |
parent | Git 2.43 (diff) | |
download | git-ba176db511b3438738a4aeb98e574310e697ff5f.tar.xz git-ba176db511b3438738a4aeb98e574310e697ff5f.zip |
config: handle NULL value when parsing non-bools
When the config parser sees an "implicit" bool like:
[core]
someVariable
it passes NULL to the config callback. Any callback code which expects a
string must check for NULL. This usually happens via helpers like
git_config_string(), etc, but some custom code forgets to do so and will
segfault.
These are all fairly vanilla cases where the solution is just the usual
pattern of:
if (!value)
return config_error_nonbool(var);
though note that in a few cases we have to split initializers like:
int some_var = initializer();
into:
int some_var;
if (!value)
return config_error_nonbool(var);
some_var = initializer();
There are still some broken instances after this patch, which I'll
address on their own in individual patches after this one.
Reported-by: Carlos Andrés Ramírez Cataño <antaigroupltda@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1386,6 +1386,8 @@ static int git_default_core_config(const char *var, const char *value, return 0; } if (!strcmp(var, "core.checkstat")) { + if (!value) + return config_error_nonbool(var); if (!strcasecmp(value, "default")) check_stat = 1; else if (!strcasecmp(value, "minimal")) @@ -1547,11 +1549,15 @@ static int git_default_core_config(const char *var, const char *value, } if (!strcmp(var, "core.checkroundtripencoding")) { + if (!value) + return config_error_nonbool(var); check_roundtrip_encoding = xstrdup(value); return 0; } if (!strcmp(var, "core.notesref")) { + if (!value) + return config_error_nonbool(var); notes_ref_name = xstrdup(value); return 0; } @@ -1619,6 +1625,8 @@ static int git_default_core_config(const char *var, const char *value, } if (!strcmp(var, "core.createobject")) { + if (!value) + return config_error_nonbool(var); if (!strcmp(value, "rename")) object_creation_mode = OBJECT_CREATION_USES_RENAMES; else if (!strcmp(value, "link")) |