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 --- diff.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 2c602df10a..5b213a4b44 100644 --- a/diff.c +++ b/diff.c @@ -372,7 +372,10 @@ int git_diff_ui_config(const char *var, const char *value, return 0; } if (!strcmp(var, "diff.colormovedws")) { - unsigned cm = parse_color_moved_ws(value); + unsigned cm; + if (!value) + return config_error_nonbool(var); + cm = parse_color_moved_ws(value); if (cm & COLOR_MOVED_WS_ERROR) return -1; diff_color_moved_ws_default = cm; @@ -426,10 +429,15 @@ int git_diff_ui_config(const char *var, const char *value, if (!strcmp(var, "diff.orderfile")) return git_config_pathname(&diff_order_file_cfg, var, value); - if (!strcmp(var, "diff.ignoresubmodules")) + if (!strcmp(var, "diff.ignoresubmodules")) { + if (!value) + return config_error_nonbool(var); handle_ignore_submodules_arg(&default_diff_options, value); + } if (!strcmp(var, "diff.submodule")) { + if (!value) + return config_error_nonbool(var); if (parse_submodule_params(&default_diff_options, value)) warning(_("Unknown value for 'diff.submodule' config variable: '%s'"), value); @@ -473,7 +481,10 @@ int git_diff_basic_config(const char *var, const char *value, } if (!strcmp(var, "diff.wserrorhighlight")) { - int val = parse_ws_error_highlight(value); + int val; + if (!value) + return config_error_nonbool(var); + val = parse_ws_error_highlight(value); if (val < 0) return -1; ws_error_highlight_default = val; @@ -490,6 +501,8 @@ int git_diff_basic_config(const char *var, const char *value, if (!strcmp(var, "diff.dirstat")) { struct strbuf errmsg = STRBUF_INIT; + if (!value) + return config_error_nonbool(var); default_diff_options.dirstat_permille = diff_dirstat_permille_default; if (parse_dirstat_params(&default_diff_options, value, &errmsg)) warning(_("Found errors in 'diff.dirstat' config variable:\n%s"), -- cgit v1.2.3 h/ath6kl/Makefile?id=355333a217541916576351446b5832fec7930566'>unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-05-10ath11k: Implement remain-on-channel supportBaochen Qiang3-0/+120
2022-05-10ath11k: Handle keepalive during WoWLAN suspend and resumeBaochen Qiang5-0/+156
2022-05-09ath11k: reset 11d state in process of recoveryWen Gong3-0/+9
2022-05-06ath11k: Fix RX de-fragmentation issue on WCN6750Manikanta Pubbisetty3-3/+23
2022-05-06ath10k: support bus and device specific API 1 BDF selectionRobert Marko1-1/+12
2022-05-06ath10k: mac: fix too long linesKalle Valo1-4/+9
2022-05-06ath11k: mac: fix too long lineKalle Valo1-4/+8
2022-05-04ath11k: Add support for targets without trustzoneManikanta Pubbisetty2-1/+186
2022-05-03netdev: reshuffle netif_napi_add() APIs to allow dropping weightJakub Kicinski2-20/+36