git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Andrey Okoshkin <a.okoshkin@samsung.com>
Cc: gitster@pobox.com, git@vger.kernel.org, pclouds@gmail.com,
	l.s.r@web.de, avarab@gmail.com, krh@redhat.com,
	rctay89@gmail.com, Ivan Arishchenko <i.arishchenk@samsung.com>,
	Mikhail Labiuk <m.labiuk@samsung.com>
Subject: [PATCH 2/4] remote: handle broken symrefs
Date: Thu, 19 Oct 2017 13:47:30 -0400	[thread overview]
Message-ID: <20171019174730.urelfyc2kj37fokg@sigill.intra.peff.net> (raw)
In-Reply-To: <20171019174452.hd3c47ocducddvgr@sigill.intra.peff.net>

It's possible for resolve_ref_unsafe() to return NULL with a
REF_ISSYMREF flag if a symref points to a broken ref.  In
this case, the read_remote_branches() function will segfault
passing the name to xstrdup().

This is hard to trigger in practice, since this function is
used as a callback to for_each_ref(), which will skip broken
refs in the first place (so it would have to be broken
racily, or for us to see a transient filesystem error).

If we see such a racy broken outcome let's treat it as "not
a symref". This is exactly the same thing that would happen
in the non-racy case (our function would not be called at
all, as for_each_ref would skip the broken symref).

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/remote.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/remote.c b/builtin/remote.c
index 4f5cac96b0..bc89623695 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -565,7 +565,7 @@ static int read_remote_branches(const char *refname,
 		item = string_list_append(rename->remote_branches, xstrdup(refname));
 		symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
 					    NULL, &flag);
-		if (flag & REF_ISSYMREF)
+		if (symref && (flag & REF_ISSYMREF))
 			item->util = xstrdup(symref);
 		else
 			item->util = NULL;
-- 
2.15.0.rc1.560.g5f0609e481


  parent reply	other threads:[~2017-10-19 17:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20171018170047epcas2p4310be357e11e194d6d08ac3bdc478ba3@epcas2p4.samsung.com>
2017-10-18 17:00 ` [PATCH] commit: check result of resolve_ref_unsafe Andrey Okoshkin
2017-10-18 18:34   ` Jeff King
2017-10-19  0:41     ` Junio C Hamano
2017-10-19  2:49       ` Jeff King
2017-10-19  9:33         ` Andrey Okoshkin
2017-10-19  9:36   ` [PATCH v2] " Andrey Okoshkin
2017-10-19 17:44     ` Jeff King
2017-10-19 17:46       ` [PATCH 1/4] test-ref-store: avoid passing NULL to printf Jeff King
2017-10-19 17:47       ` Jeff King [this message]
2017-10-19 17:53         ` [PATCH 2/4] remote: handle broken symrefs Jeff King
2017-10-19 17:49       ` [PATCH 3/4] log: handle broken HEAD in decoration check Jeff King
2017-10-19 17:49       ` [PATCH 4/4] worktree: handle broken symrefs in find_shared_symref() Jeff King
2017-10-21 10:49         ` Eric Sunshine
2017-10-21 19:26           ` Jeff King
2017-10-22  0:46             ` Junio C Hamano
2017-10-20 10:40       ` [PATCH v2] commit: check result of resolve_ref_unsafe Andrey Okoshkin
2017-10-20 11:03       ` [PATCH v3] " Andrey Okoshkin
2017-10-20 13:09         ` [PATCH v4] " Andrey Okoshkin
2017-10-21  6:19           ` Jeff King
2017-10-22  0:46             ` Junio C Hamano

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=20171019174730.urelfyc2kj37fokg@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=a.okoshkin@samsung.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=i.arishchenk@samsung.com \
    --cc=krh@redhat.com \
    --cc=l.s.r@web.de \
    --cc=m.labiuk@samsung.com \
    --cc=pclouds@gmail.com \
    --cc=rctay89@gmail.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).