remote: handle broken symrefs
authorJeff King <peff@peff.net>
Thu, 19 Oct 2017 17:47:30 +0000 (13:47 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 21 Oct 2017 12:29:02 +0000 (21:29 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/remote.c
index 4f5cac96b0f5e0044ddf0fd1e2ea686f694d62ca..bc896236952079fc3ae06e23101991169dea64fc 100644 (file)
@@ -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;