am: check return value of resolve_refdup before using hash
authorRené Scharfe <l.s.r@web.de>
Sat, 6 May 2017 17:13:56 +0000 (19:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 02:12:42 +0000 (11:12 +0900)
If resolve_refdup() fails it returns NULL and possibly leaves its hash
output parameter untouched. Make sure to use it only if the function
succeeded, in order to avoid accessing uninitialized memory.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c
index 31fb60578f6caacfb376fe84938dda9432dcfc5a..695968622a88771db584cb9dd394de48f361bbd3 100644 (file)
@@ -2157,7 +2157,7 @@ static void am_abort(struct am_state *state)
        am_rerere_clear();
 
        curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
-       has_curr_head = !is_null_oid(&curr_head);
+       has_curr_head = curr_branch && !is_null_oid(&curr_head);
        if (!has_curr_head)
                hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);