Skip to content

Commit 92f9e27

Browse files
jaysoffiangitster
authored andcommitted
blame: prevent a segv when -L given start > EOF
blame would segv if given -L <lineno> with <lineno> past the end of the file. While we're fixing the bug, add test cases for an invalid <start> when called as -L <start>,<end> or -L<start>. Signed-off-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 153559a commit 92f9e27

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

builtin-blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
24322432
if (top < 1)
24332433
top = lno;
24342434
bottom--;
2435-
if (lno < top)
2435+
if (lno < top || lno < bottom)
24362436
die("file %s has only %lu lines", path, lno);
24372437

24382438
ent = xcalloc(1, sizeof(*ent));

t/t8003-blame.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ EOF
157157
git --no-pager blame $COMMIT -- uno >/dev/null
158158
'
159159

160+
test_expect_success 'blame -L with invalid start' '
161+
test_must_fail git blame -L5 tres 2>&1 | grep "has only 2 lines"
162+
'
163+
164+
test_expect_success 'blame -L with invalid end' '
165+
git blame -L1,5 tres 2>&1 | grep "has only 2 lines"
166+
'
167+
160168
test_done

0 commit comments

Comments
 (0)