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

[PATCH] Small correction in reading of commit headers

From
Alex Riesen <raa.lkml@gmail.com>
Date
May 4, 2007, 21:51 UTC
Message-ID
<20070504215132.GD4033@steel.home>

Check if a line of the header has enough characters to possibly contain the requested prefix.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

Noticed by debugging git-log crash in broken repos with missing packs. It happened to be up in backtrace. At the moment the optimization is actually a slow down: no line in the header is shorter than the only key this function is ever asked for: encoding. But, in case the function ever gets asked for something longer, the old condition is just wrong: it does not take into account the amount of data in the line when comparing with key.

 commit.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/commit.c b/commit.c
index aa7059c..d01833d 100644
--- a/commit.c
+++ b/commit.c
@@ -638,7 +638,9 @@ static char *get_header(const struct commit *commit, const char *key)
 			next = NULL;
 		} else
 			next = eol + 1;
-		if (!strncmp(line, key, key_len) && line[key_len] == ' ') {
+		if (eol - line > key_len &&
+		    !strncmp(line, key, key_len) &&
+		    line[key_len] == ' ') {
 			int len = eol - line - key_len;
 			char *ret = xmalloc(len);
 			memcpy(ret, line + key_len + 1, len - 1);
-- 
1.5.2.rc1.21.g80e79
Message 1 of 1 in “Small correction in reading of commit headers”
  1. Small correction in reading of commit headersAlex Riesen, May 4, 2007

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.