From: Thomas Bachem via GitGitGadget Date: Wed, 11 Nov 2026 22:49:05 GMT Subject: [PATCH v3 05/15] grep: handle NULL value for grep.patternType Message-ID: <123f03f024ce442a82a1900e03d21951e06d0cd7.1794437355.git.gitgitgadget@gmail.com> In-Reply-To: From: Thomas Bachem A grep.patternType without a value makes "git grep", "git log" and "git show" segfault: grep_config(), which all three use, passes the NULL value to parse_pattern_type_arg(), which hands it to strcmp(). Reject a missing value with config_error_nonbool(), as grep_config() already does for the color.grep.* slots. Assisted-by: Claude Fable 5.1 Signed-off-by: Thomas Bachem --- grep.c | 2 ++ t/t7810-grep.sh | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/grep.c b/grep.c index 1d75d31421..ab082f963e 100644 --- a/grep.c +++ b/grep.c @@ -71,6 +71,8 @@ int grep_config(const char *var, const char *value, } if (!strcmp(var, "grep.patterntype")) { + if (!value) + return config_error_nonbool(var); opt->pattern_type_option = parse_pattern_type_arg(var, value); return 0; } diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index ac7ea9cf8d..d323927e54 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1551,6 +1551,11 @@ test_expect_success PCRE 'grep invalidpattern properly dies with grep.patternTyp test_must_fail git -c grep.patterntype=perl grep "a[" ' +test_expect_success 'grep.patternType without a value is rejected' ' + test_must_fail git -c grep.patternType grep "a" 2>err && + test_grep "missing value for .grep.patterntype." err +' + test_expect_success 'grep -G -E -F pattern' ' echo "ab:a+b*c" >expected && git grep -G -E -F "a+b*c" ab >actual && -- gitgitgadget