From: Jeff King Date: Thu, 24 Sep 2015 21:02:54 +0000 (-0400) Subject: show-branch: avoid segfault with --reflog of unborn branch X-Git-Tag: v2.8.3~32^2~26 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7cd17e80579c2bffd6245837175a6e1b12a78045?hp=--cc 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 Signed-off-by: Junio C Hamano --- 7cd17e80579c2bffd6245837175a6e1b12a78045 diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 408ce70307..092b59b0b3 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -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");