Skip to content

Commit d79be49

Browse files
peffgitster
authored andcommitted
log: handle broken HEAD in decoration check
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 752848d commit d79be49

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

log-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
198198

199199
/* Now resolve and find the matching current branch */
200200
branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags);
201-
if (!(rru_flags & REF_ISSYMREF))
201+
if (!branch_name || !(rru_flags & REF_ISSYMREF))
202202
return NULL;
203203

204204
if (!starts_with(branch_name, "refs/"))

0 commit comments

Comments
 (0)