@matheusbsbs / matheus-bagliano / commits / 92f9e273e8
Fork 0

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 <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jay Soffian committed Feb 8, 2010 at 22:48 UTC 92f9e273e86d505e4c2a28bc053eb514ca2cc552
2 files changed +9 -1
builtin-blame.c
+1 -1
@@ -2432,7 +2432,7 @@ parse_done:
2432 if (top < 1)
2433 top = lno;
2434 bottom--;
2435 - if (lno < top)
2435 + if (lno < top || lno < bottom)
2436 die("file %s has only %lu lines", path, lno);
2437
2438 ent = xcalloc(1, sizeof(*ent));
t/t8003-blame.sh
+8
@@ -157,4 +157,12 @@ EOF
157 git --no-pager blame $COMMIT -- uno >/dev/null
158 '
159
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 +
168 test_done