Skip to content

Commit 752848d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc61cf4 commit 752848d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static int read_remote_branches(const char *refname,
565565
item = string_list_append(rename->remote_branches, xstrdup(refname));
566566
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
567567
NULL, &flag);
568-
if (flag & REF_ISSYMREF)
568+
if (symref && (flag & REF_ISSYMREF))
569569
item->util = xstrdup(symref);
570570
else
571571
item->util = NULL;

0 commit comments

Comments
 (0)