Git fork

Merge branch 'ps/build-sign-compare'

Last-minute fix for a regression in "git blame --abbrev=<length>"
when insane <length> is specified; we used to correctly cap it to
the hash output length but broke it during the cycle.

* ps/build-sign-compare:
builtin/blame: fix out-of-bounds write with blank boundary commits
builtin/blame: fix out-of-bounds read with excessive `--abbrev`

+31 -4
+5 -4
builtin/blame.c
··· 489 489 fputs(color, stdout); 490 490 491 491 if (suspect->commit->object.flags & UNINTERESTING) { 492 - if (blank_boundary) 493 - memset(hex, ' ', length); 494 - else if (!(opt & OUTPUT_ANNOTATE_COMPAT)) { 492 + if (blank_boundary) { 493 + memset(hex, ' ', strlen(hex)); 494 + } else if (!(opt & OUTPUT_ANNOTATE_COMPAT)) { 495 495 length--; 496 496 putchar('^'); 497 497 } ··· 505 505 length--; 506 506 putchar('?'); 507 507 } 508 - fwrite(hex, 1, length, stdout); 508 + 509 + printf("%.*s", (int)(length < GIT_MAX_HEXSZ ? length : GIT_MAX_HEXSZ), hex); 509 510 if (opt & OUTPUT_ANNOTATE_COMPAT) { 510 511 const char *name; 511 512 if (opt & OUTPUT_SHOW_EMAIL)
+26
t/t8002-blame.sh
··· 126 126 check_abbrev $hexsz --no-abbrev 127 127 ' 128 128 129 + test_expect_success 'blame --abbrev gets truncated' ' 130 + check_abbrev $hexsz --abbrev=9000 HEAD 131 + ' 132 + 133 + test_expect_success 'blame --abbrev gets truncated with boundary commit' ' 134 + check_abbrev $hexsz --abbrev=9000 ^HEAD 135 + ' 136 + 137 + test_expect_success 'blame --abbrev -b truncates the blank boundary' ' 138 + # Note that `--abbrev=` always gets incremented by 1, which is why we 139 + # expect 11 leading spaces and not 10. 140 + cat >expect <<-EOF && 141 + $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev 142 + EOF 143 + git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual && 144 + test_cmp expect actual 145 + ' 146 + 147 + test_expect_success 'blame with excessive --abbrev and -b culls to hash length' ' 148 + cat >expect <<-EOF && 149 + $(printf "%0.s " $(test_seq $hexsz)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev 150 + EOF 151 + git blame -b --abbrev=9000 ^HEAD -- abbrev.t >actual && 152 + test_cmp expect actual 153 + ' 154 + 129 155 test_expect_success '--exclude-promisor-objects does not BUG-crash' ' 130 156 test_must_fail git blame --exclude-promisor-objects one 131 157 '