git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Clemens Buchacher <drizzd@aon.at>
To: Erik Faye-Lund <kusmabite@googlemail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Segfault in "git remote show <remote-name>"
Date: Mon, 25 May 2009 21:01:21 +0200	[thread overview]
Message-ID: <20090525190121.GA3979@localhost> (raw)
In-Reply-To: <40aa078e0905250910v268faa66p29a0183db26cb0df@mail.gmail.com>

Subject: [PATCH] fix segfault showing an empty remote

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

Reported-by: Erik Faye-Lund <kusmabite@googlemail.com>
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---

On Mon, May 25, 2009 at 06:10:12PM +0200, Erik Faye-Lund wrote:
> I've been messing around a bit, trying to set up a gitosis repo to
> mirror one of my projects. Now, I added the remote to my project, but
> when running "git remote show <remote-name>", I'm getting a segfault
> in builtin-remote.c at line 303 ("while (ref->next)"), because ref
> itself is NULL.

This should fix it.

I simply copied this from other uses of match_refs. I wonder if this calls
for a find_link_ref_tail() function, but I didn't know where to put it.

Clemens

 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

  reply	other threads:[~2009-05-25 19:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-25 16:10 Segfault in "git remote show <remote-name>" Erik Faye-Lund
2009-05-25 19:01 ` Clemens Buchacher [this message]
2009-05-26 14:27   ` Jay Soffian
2009-05-27 20:13     ` [PATCH 1/2] fix segfault showing an empty remote Clemens Buchacher
2009-05-27 20:13       ` [PATCH 2/2] match_refs: search ref list tail internally Clemens Buchacher
2009-05-28  7:06         ` Junio C Hamano
2009-05-28  9:26           ` Clemens Buchacher
2009-05-31 14:26           ` [PATCH v2] " Clemens Buchacher
2009-05-26 18:54   ` Segfault in "git remote show <remote-name>" Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090525190121.GA3979@localhost \
    --to=drizzd@aon.at \
    --cc=git@vger.kernel.org \
    --cc=kusmabite@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).