git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] blame: prevent a segv when -L given start > EOF

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 9, 2010, 17:59 UTC
Message-ID
<1265738392-61503-1-git-send-email-jaysoffian@gmail.com>
In-Reply-To
<4B71122F.3040809@viscovery.net>

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>
---
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
Previous: Junio C Hamano
Message 11 of 11 in “blame: prevent a segv when -L given start > EOF”
  1. blame: prevent a segv when -L given start > EOFJay Soffian, Feb 9, 2010
  2. Jay SoffianFeb 9, 2010
  3. Junio C HamanoFeb 9, 2010
  4. Jay SoffianFeb 9, 2010
  5. Jay SoffianFeb 9, 2010
  6. Jay SoffianFeb 9, 2010
  7. Junio C HamanoFeb 9, 2010
  8. Johannes SixtFeb 9, 2010
  9. Jay SoffianFeb 9, 2010
  10. Junio C HamanoFeb 9, 2010
  11. blame: prevent a segv when -L given start > EOFJay Soffian, Feb 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.