log: handle broken HEAD in decoration check
authorJeff King <peff@peff.net>
Thu, 19 Oct 2017 17:49:01 +0000 (13:49 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 21 Oct 2017 12:29:37 +0000 (21:29 +0900)
The resolve_ref_unsafe() function may return NULL even with
a REF_ISSYMREF flag if a symref points to a broken ref. As a
result, it's possible for the decoration code's "is this
branch the current HEAD" check to segfault when it passes
the NULL to starts_with().

This is unlikely in practice, since we can only reach this
code if we already resolved HEAD to a matching sha1 earlier.
But it's possible if HEAD racily becomes broken, or if
there's a transient filesystem error.

We can fix this by returning early in the broken case, since
NULL could not possibly match any of our branch names.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
log-tree.c
index cea056234d0a0b605c988a4e157852cd659f22ef..580b3a98a03df8b1920b3f729c783b79ed781164 100644 (file)
@@ -198,7 +198,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
 
        /* Now resolve and find the matching current branch */
        branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags);
-       if (!(rru_flags & REF_ISSYMREF))
+       if (!branch_name || !(rru_flags & REF_ISSYMREF))
                return NULL;
 
        if (!starts_with(branch_name, "refs/"))