From: Thomas Bachem via GitGitGadget Date: Sat, 07 Nov 2026 08:42:47 GMT Subject: [PATCH 15/15] config: handle NULL values when listing colors and expiry dates Message-ID: <7ac4e3a3d9caded1a857dc415f05931330a5d366.1794040968.git.gitgitgadget@gmail.com> In-Reply-To: From: Thomas Bachem Since 2d4ab5a885 (config: format colors quietly, 2026-02-23) and 9cb4a5e1ba (config: format expiry dates quietly, 2026-02-23), "git config list --type=color" and "--type=expiry-date" pass every value to color_parse_quietly() or parse_expiry_date(), which do not handle NULL. So both segfault when any key in the configuration has no value. Skip such a key quietly, as both already do with a value that does not parse, and as "--type=int" does with a key without a value. Assisted-by: Claude Opus 5.5 Signed-off-by: Thomas Bachem --- builtin/config.c | 4 ++-- t/t1300-config.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 2554322317..f786c0b123 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -366,7 +366,7 @@ static int format_config_expiry_date(struct strbuf *buf, { timestamp_t t; if (quietly) { - if (parse_expiry_date(value_, &t)) + if (!value_ || parse_expiry_date(value_, &t)) return -1; } else if (git_config_expiry_date(&t, key_, value_) < 0) { return -1; @@ -384,7 +384,7 @@ static int format_config_color(struct strbuf *buf, char v[COLOR_MAXLEN]; if (gently) { - if (color_parse_quietly(value_, v) < 0) + if (!value_ || color_parse_quietly(value_, v) < 0) return -1; } else if (git_config_color(v, key_, value_) < 0) { return -1; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 8fb920b1ba..3322b0bf4f 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2648,6 +2648,16 @@ test_expect_success 'list --type=color shows only canonicalizable color values' test_must_be_empty err ' +test_expect_success 'list --type=color and --type=expiry-date skip keys without a value' ' + git -c section.valueless config ${mode_prefix}list --type=color >actual 2>err && + test_grep ! valueless actual && + test_must_be_empty err && + + git -c section.valueless config ${mode_prefix}list --type=expiry-date >actual 2>err && + test_grep ! valueless actual && + test_must_be_empty err +' + test_expect_success '--type rejects unknown specifiers' ' test_must_fail git config --type=nonsense section.foo 2>error && test_grep "unrecognized --type argument" error -- gitgitgadget