Skip to content

Commit 9e231ff

Browse files
committed
Merge branch 'ps/build-sign-compare' into jch
* ps/build-sign-compare: SQUASH??? builtin/blame: fix out-of-bounds read with excessive `--abbrev`
2 parents d1e06a9 + 284bf70 commit 9e231ff

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

builtin/blame.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,10 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
505505
length--;
506506
putchar('?');
507507
}
508-
fwrite(hex, 1, length, stdout);
508+
509+
if (length > GIT_MAX_HEXSZ)
510+
length = GIT_MAX_HEXSZ;
511+
printf("%.*s", (int)length, hex);
509512
if (opt & OUTPUT_ANNOTATE_COMPAT) {
510513
const char *name;
511514
if (opt & OUTPUT_SHOW_EMAIL)

t/t8002-blame.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ test_expect_success '--no-abbrev works like --abbrev with full length' '
126126
check_abbrev $hexsz --no-abbrev
127127
'
128128

129+
test_expect_success 'blame --abbrev gets truncated' '
130+
check_abbrev $hexsz --abbrev=9000 HEAD &&
131+
check_abbrev $hexsz --abbrev=9000 HEAD..
132+
'
133+
129134
test_expect_success '--exclude-promisor-objects does not BUG-crash' '
130135
test_must_fail git blame --exclude-promisor-objects one
131136
'

0 commit comments

Comments
 (0)