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

[PATCH 1/2] fix segfault showing an empty remote

From
Clemens Buchacher <drizzd@aon.at>
Date
May 27, 2009, 20:13 UTC
Message-ID
<1243455224-3463-1-git-send-email-drizzd@aon.at>
In-Reply-To
<76718490905260727v7261391uab169167978e4522@mail.gmail.com>

In case of an empty list, the search for its tail caused a NULL-pointer dereference.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Reported-by: Erik Faye-Lund <kusmabite@googlemail.com>
Acked-by: Jay Soffian <jaysoffian@gmail.com>
---
 builtin-remote.c  |    8 ++++----
 t/t5505-remote.sh |   10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 71abf68..fda9a54 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -299,11 +299,11 @@ static int get_push_ref_states(const struct ref *remote_refs,
 		return 0;
 
 	local_refs = get_local_heads();
-	ref = push_map = copy_ref_list(remote_refs);
-	while (ref->next)
-		ref = ref->next;
-	push_tail = &ref->next;
+	push_map = copy_ref_list(remote_refs);
 
+	push_tail = &push_map;
+	while (*push_tail)
+		push_tail = &((*push_tail)->next);
 	match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr,
 		   remote->push_refspec, MATCH_REFS_NONE);
 
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 5ec668d..e70246b 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -494,5 +494,15 @@ test_expect_success 'remote prune to cause a dangling symref' '
 	grep "dangling symref" err
 '
 
+test_expect_success 'show empty remote' '
+
+	test_create_repo empty &&
+	git clone empty empty-clone &&
+	(
+		cd empty-clone &&
+		git remote show origin
+	)
+'
+
 test_done
 
-- 
1.6.3.1.147.g637c3
Previous: Jay SoffianNext: Clemens Buchacher
Message 4 of 9 in “Segfault in "git remote show <remote-name>"”
  1. Erik Faye-LundMay 25, 2009
  2. Clemens BuchacherMay 25, 2009
  3. Jay SoffianMay 26, 2009
  4. 1/2 fix segfault showing an empty remoteClemens Buchacher, May 27, 2009
  5. 2/2 match_refs: search ref list tail internallyClemens Buchacher, May 27, 2009
  6. Junio C HamanoMay 28, 2009
  7. Clemens BuchacherMay 28, 2009
  8. match_refs: search ref list tail internallyClemens Buchacher, May 31, 2009
  9. Erik Faye-LundMay 26, 2009

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.