am: check return value of resolve_refdup before using hash

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>

René Scharfe committed May 6, 2017 at 19:13 UTC 57e0ef0e0e90c4cb72c35db874fc3d035b88ce4d
1 file changed +1 -1
builtin/am.c
+1 -1
@@ -2157,7 +2157,7 @@ static void am_abort(struct am_state *state)
2157 am_rerere_clear();
2158
2159 curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
2160 - has_curr_head = !is_null_oid(&curr_head);
2160 + has_curr_head = curr_branch && !is_null_oid(&curr_head);
2161 if (!has_curr_head)
2162 hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
2163