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

[PATCH] Fix segfault for insane ident line

From
Jiang Xin <worldhello.net@gmail.com>
Date
Apr 25, 2013, 10:32 UTC
Message-ID
<e7453e2b99517ebed045d82be4d5f2c9388bb002.1366885748.git.worldhello.net@gmail.com>
In-Reply-To
<cover.1366885748.git.worldhello.net@gmail.com>

An insane ident line (generated by old version of git or by hands such as git-hash-object) may cause segfault for `git log` and others commands.

This is because the `split_ident_line` function save the result in ident_split, and the returned ident_split.date_begin, ident_split.date_end, ident_split.tz_begin, and ident_split.tz_end maybe NULL pointers for an insame ident line.

This issue was was introduced in v1.8.1-rc1-7-g3c020bd (Use split_ident_line to parse author and committer).

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
---
 builtin/blame.c | 14 +++++++++++---
 pretty.c        |  9 +++++++--
 2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 86100..4b94e 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1375,10 +1375,18 @@ static void get_ac_line(const char *inbuf, const char *what,
 	maillen = ident.mail_end - ident.mail_begin;
 	mailbuf = ident.mail_begin;
 
-	*time = strtoul(ident.date_begin, NULL, 10);
+	if (ident.date_begin != NULL) {
+		*time = strtoul(ident.date_begin, NULL, 10);
+	} else {
+		*time = 0;
+	}
 
-	len = ident.tz_end - ident.tz_begin;
-	strbuf_add(tz, ident.tz_begin, len);
+	if (ident.tz_begin != NULL && ident.tz_end !=NULL) {
+		len = ident.tz_end - ident.tz_begin;
+		strbuf_add(tz, ident.tz_begin, len);
+	} else {
+		strbuf_addstr(tz, "(unknown)");
+	}
 
 	/*
 	 * Now, convert both name and e-mail using mailmap
diff --git a/pretty.c b/pretty.c
index d3a82..2402f 100644
--- a/pretty.c
+++ b/pretty.c
@@ -438,8 +438,13 @@ void pp_user_info(const struct pretty_print_context *pp,
 	strbuf_add(&name, namebuf, namelen);
 
 	namelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */
-	time = strtoul(ident.date_begin, &date, 10);
-	tz = strtol(date, NULL, 10);
+	if (ident.date_begin != NULL) {
+		time = strtoul(ident.date_begin, &date, 10);
+		tz = strtol(date, NULL, 10);
+	} else {
+		time = 0;
+		tz = 0;
+	}
 
 	if (pp->fmt == CMIT_FMT_EMAIL) {
 		strbuf_addstr(sb, "From: ");
-- 
1.8.2.1.348.gb94490b
Previous: Jiang XinNext: Jiang Xin
Message 2 of 3 in “Fix segfault for insane ident line”
  1. Fix segfault for insane ident lineJiang Xin, Apr 25, 2013
  2. Fix segfault for insane ident lineJiang Xin, Apr 25, 2013
  3. Jiang XinApr 25, 2013

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.