From ba176db511b3438738a4aeb98e574310e697ff5f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 7 Dec 2023 02:11:14 -0500 Subject: config: handle NULL value when parsing non-bools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- config.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index b330c7adb4..18085c7e38 100644 --- a/config.c +++ b/config.c @@ -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")) -- cgit v1.2.3