summaryrefslogtreecommitdiff
path: root/builtin/remote.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-10-19 17:47:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-10-21 12:29:02 (GMT)
commit752848df0f18a9f8eb808a5b54c862c176d86e6d (patch)
treefdfb014a8dd371de3b456d389da65e4354e402a1 /builtin/remote.c
parentcc61cf465f7777d0aebd1a35ca72650fef8f253f (diff)
downloadgit-752848df0f18a9f8eb808a5b54c862c176d86e6d.zip
git-752848df0f18a9f8eb808a5b54c862c176d86e6d.tar.gz
git-752848df0f18a9f8eb808a5b54c862c176d86e6d.tar.bz2
remote: handle broken symrefs
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>
Diffstat (limited to 'builtin/remote.c')
-rw-r--r--builtin/remote.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index 4f5cac9..bc89623 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;