push: fix segfault when HEAD points nowhere
authorFraser Tweedale <frase@frase.id.au>
Thu, 31 Jan 2013 12:22:51 +0000 (22:22 +1000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 31 Jan 2013 16:09:53 +0000 (08:09 -0800)
After a push of a branch other than the current branch fails in
a no-ff error and if you are still on an unborn branch, the code
recently added to report the failure dereferenced a null pointer
while checking the name of the current branch.

Signed-off-by: Fraser Tweedale <frase@frase.id.au>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
transport.c

index 7864007c9c689c4674730b2bccf6f5212b726501..af442af329275a693fa713aa5ae9af759f4d4a2a 100644 (file)
@@ -744,7 +744,7 @@ void transport_print_push_status(const char *dest, struct ref *refs,
                        n += print_one_push_status(ref, dest, n, porcelain);
                if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD &&
                    *nonfastforward != NON_FF_HEAD) {
-                       if (!strcmp(head, ref->name))
+                       if (head != NULL && !strcmp(head, ref->name))
                                *nonfastforward = NON_FF_HEAD;
                        else
                                *nonfastforward = NON_FF_OTHER;