Skip to content

Commit

Permalink
show-branch: avoid segfault with --reflog of unborn branch
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 25, 2015
1 parent 8d530c4 commit 7cd17e8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
fake_av[1] = NULL;
av = fake_av;
ac = 1;
if (!*av)
die("no branches given, and HEAD is not valid");
}
if (ac != 1)
die("--reflog option needs one branch name");
Expand Down

0 comments on commit 7cd17e8

Please sign in to comment.