]> git.ipfire.org Git - thirdparty/git.git/commitdiff
show-branch: avoid segfault with --reflog of unborn branch
authorJeff King <peff@peff.net>
Thu, 24 Sep 2015 21:02:54 +0000 (17:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 Sep 2015 17:18:18 +0000 (10:18 -0700)
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>
builtin/show-branch.c

index 408ce7030731f765228de93066a815bd4db59e30..092b59b0b3c0782a9802b9c3200d5523ac4e2e3e 100644 (file)
@@ -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");