[PATCH 07/15] blame: handle NULL values for color.blame.* config
- From
Thomas Bachem via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Nov 7, 2026, 08:42 UTC
- Message-ID
- <260b90a4a23d9a94aea0ed2a2e28930a646d7fd6.1794040968.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2297.git.1794040967.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
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().
Reject a missing value with config_error_nonbool(), as git_blame_config() already does for blame.date and blame.coloring.
Assisted-by: Claude Fable 5.1 Signed-off-by: Thomas Bachem <mail@thomasbachem.com> --- builtin/blame.c | 4 ++++ t/t8012-blame-colors.sh | 7 +++++++ 2 files changed, 11 insertions(+)
diff --git a/builtin/blame.c b/builtin/blame.c index 48d5251c6d..653449c0c9 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -782,12 +782,16 @@ static int git_blame_config(const char *var, const char *value, return 0; } if (!strcmp(var, "color.blame.repeatedlines")) { + if (!value) + return config_error_nonbool(var); 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..5eeb7338a3 100755 --- a/t/t8012-blame-colors.sh +++ b/t/t8012-blame-colors.sh @@ -69,4 +69,11 @@ test_expect_success 'blame color by age: new code is different' ' test_grep qfunc colored ' +test_expect_success 'color.blame.repeatedLines and highlightRecent need a value' ' + test_must_fail git -c color.blame.repeatedLines blame hello.c 2>err && + test_grep "missing value for .color.blame.repeatedlines." err && + 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