Skip to content

Commit 7cd17e8

Browse files
peffgitster
authored andcommitted
show-branch: avoid segfault with --reflog of unborn branch
When no branch is given to the "--reflog" option, we resolve HEAD to get the default branch. However, if HEAD points to an unborn branch, resolve_ref returns NULL, and we later segfault trying to access it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d530c4 commit 7cd17e8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/show-branch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
743743
fake_av[1] = NULL;
744744
av = fake_av;
745745
ac = 1;
746+
if (!*av)
747+
die("no branches given, and HEAD is not valid");
746748
}
747749
if (ac != 1)
748750
die("--reflog option needs one branch name");

0 commit comments

Comments
 (0)