git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blame: prevent a segv when -L given start > EOF
@ 2010-02-09  3:48 Jay Soffian
  2010-02-09  3:50 ` Jay Soffian
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jay Soffian @ 2010-02-09  3:48 UTC (permalink / raw)
  To: git, Junio C Hamano; +Cc: Jay Soffian

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>
---
bottom is start and top is end, which seems backwards to me, but alas, it is
what it is. :-)

 builtin-blame.c  |    2 +-
 t/t8003-blame.sh |    8 ++++++++
 2 files changed, 9 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..4a8db74 100755
--- a/t/t8003-blame.sh
+++ b/t/t8003-blame.sh
@@ -157,4 +157,12 @@ EOF
   git --no-pager blame $COMMIT -- uno >/dev/null
 '
 
+test_expect_success 'blame -L with invalid start' '
+	test_must_fail git blame -L5 tres 2>&1 | grep "has only 2 lines"
+'
+
+test_expect_success 'blame -L with invalid end' '
+	git blame -L1,5 tres 2>&1 | grep "has only 2 lines"
+'
+
 test_done
-- 
1.7.0.rc1.200.g9c1f9

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-02-09 18:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-09  3:48 [PATCH] blame: prevent a segv when -L given start > EOF Jay Soffian
2010-02-09  3:50 ` Jay Soffian
2010-02-09  3:55 ` Junio C Hamano
2010-02-09  4:00   ` Jay Soffian
2010-02-09  4:02     ` Jay Soffian
2010-02-09  4:09   ` Jay Soffian
2010-02-09  5:55   ` Junio C Hamano
2010-02-09  7:43 ` Johannes Sixt
2010-02-09 17:55   ` Jay Soffian
2010-02-09 18:06     ` Junio C Hamano
2010-02-09 17:59   ` [PATCH v2] " Jay Soffian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).