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

[PATCH] Fix segfaults caused by invalid tags

From
Petr Baudis <pasky@suse.cz>
Date
Nov 2, 2005, 20:07 UTC
Message-ID
<20051102200751.26904.5780.stgit@machine.or.cz>

On many places, we didn't bother checking deref_tag() return value against NULL, causing GIT segfaulting e.g. on some old Cogito checkouts containing residual tags from GIT.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 fetch-pack.c  |    2 +-
 server-info.c |    5 +++--
 upload-pack.c |    3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 3df9911..1fae211 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -40,7 +40,7 @@ static int rev_list_insert_ref(const cha
 {
 	struct object *o = deref_tag(parse_object(sha1));
 
-	if (o->type == commit_type)
+	if (o && o->type == commit_type)
 		rev_list_push((struct commit *)o, SEEN);
 
 	return 0;
diff --git a/server-info.c b/server-info.c
index ba53591..8e13c94 100644
--- a/server-info.c
+++ b/server-info.c
@@ -14,8 +14,9 @@ static int add_info_ref(const char *path
 	fprintf(info_ref_fp, "%s	%s\n", sha1_to_hex(sha1), path);
 	if (o->type == tag_type) {
 		o = deref_tag(o);
-		fprintf(info_ref_fp, "%s	%s^{}\n",
-			sha1_to_hex(o->sha1), path);
+		if (o)
+			fprintf(info_ref_fp, "%s	%s^{}\n",
+				sha1_to_hex(o->sha1), path);
 	}
 	return 0;
 }
diff --git a/upload-pack.c b/upload-pack.c
index c5eff21..f0b8e63 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -227,7 +227,8 @@ static int send_ref(const char *refname,
 	}
 	if (o->type == tag_type) {
 		o = deref_tag(o);
-		packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
+		if (o)
+			packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
 	}
 	return 0;
 }
Next: Johannes Schindelin
Message 1 of 9 in “Fix segfaults caused by invalid tags”
  1. Fix segfaults caused by invalid tagsPetr Baudis, Nov 2, 2005
  2. Johannes SchindelinNov 2, 2005
  3. Junio C HamanoNov 2, 2005
  4. Warn when calling deref_tag() on broken tagsPetr Baudis, Nov 2, 2005
  5. Johannes SchindelinNov 2, 2005
  6. Petr BaudisNov 2, 2005
  7. Junio C HamanoNov 2, 2005
  8. Junio C HamanoNov 2, 2005
  9. Petr BaudisNov 2, 2005

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.