From: Thomas Bachem via GitGitGadget Date: Wed, 11 Nov 2026 22:49:07 GMT Subject: [PATCH v3 07/15] blame: handle NULL values for color.blame.* config Message-ID: In-Reply-To: From: Thomas Bachem A color.blame.repeatedLines or color.blame.highlightRecent without a value makes "git blame" segfault: git_blame_config() passes the NULL value to strlen() or to parse_color_fields(). An invalid color.blame.repeatedLines gets a warning and is ignored. Treat a missing value the same way. An invalid color.blame.highlightRecent makes "git blame" die, so reject a missing value there with config_error_nonbool(), as git_blame_config() already does for blame.date and blame.coloring. Helped-by: Phillip Wood Assisted-by: Claude Fable 5.1 Assisted-by: Claude Opus 5.5 Signed-off-by: Thomas Bachem --- builtin/blame.c | 7 +++++++ t/t8012-blame-colors.sh | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/builtin/blame.c b/builtin/blame.c index 1e753a0b60..55a3151942 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -783,12 +783,19 @@ static int git_blame_config(const char *var, const char *value, return 0; } if (!strcmp(var, "color.blame.repeatedlines")) { + if (!value) { + warning(_("missing value for '%s'"), + "color.blame.repeatedLines"); + return 0; + } if (color_parse_mem(value, strlen(value), repeated_meta_color)) warning(_("invalid value for '%s': '%s'"), "color.blame.repeatedLines", value); return 0; } if (!strcmp(var, "color.blame.highlightrecent")) { + if (!value) + return config_error_nonbool(var); parse_color_fields(value); return 0; } diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh index d2653b3c31..2024047c85 100755 --- a/t/t8012-blame-colors.sh +++ b/t/t8012-blame-colors.sh @@ -69,4 +69,16 @@ test_expect_success 'blame color by age: new code is different' ' test_grep qfunc colored ' +test_expect_success 'color.blame.repeatedLines without a value only warns' ' + git blame --color-lines hello.c >expect && + git -c color.blame.repeatedLines blame --color-lines hello.c >actual 2>err && + test_cmp expect actual && + test_grep "missing value for .color.blame.repeatedLines." err +' + +test_expect_success 'color.blame.highlightRecent needs a value' ' + test_must_fail git -c color.blame.highlightRecent blame hello.c 2>err && + test_grep "missing value for .color.blame.highlightrecent." err +' + test_done -- gitgitgadget