From: Jay Soffian Date: Tue, 09 Feb 2010 17:59:52 GMT Subject: [PATCH v2] blame: prevent a segv when -L given start > EOF Message-ID: <1265738392-61503-1-git-send-email-jaysoffian@gmail.com> In-Reply-To: <4B71122F.3040809@viscovery.net> blame would segv if given -L with past the end of the file. While we're fixing the bug, add test cases for an invalid when called as -L , or -L. Signed-off-by: Jay Soffian --- Modified the tests per Hannes recommendations. builtin-blame.c | 2 +- t/t8003-blame.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 6408ec8..10f7eac 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -2433,7 +2433,7 @@ parse_done: if (top < 1) top = lno; bottom--; - if (lno < top) + if (lno < top || lno < bottom) die("file %s has only %lu lines", path, lno); ent = xcalloc(1, sizeof(*ent)); diff --git a/t/t8003-blame.sh b/t/t8003-blame.sh index ad834f2..be648b2 100755 --- a/t/t8003-blame.sh +++ b/t/t8003-blame.sh @@ -157,4 +157,14 @@ EOF git --no-pager blame $COMMIT -- uno >/dev/null ' +test_expect_success 'blame -L with invalid start' ' + test_must_fail git blame -L5 tres >output 2>&1 && + grep "has only 2 lines" output +' + +test_expect_success 'blame -L with invalid end' ' + test_must_fail git blame -L1,5 tres >output 2>&1 && + grep "has only 2 lines" output +' + test_done -- 1.7.0.rc1.200.g9c1f9