Skip to content

Commit a207ad7

Browse files
committed
Merge branch 'rs/checkout-am-fix-unborn' into maint
A few codepaths in "checkout" and "am" working on an unborn branch tried to access an uninitialized piece of memory. * rs/checkout-am-fix-unborn: am: check return value of resolve_refdup before using hash checkout: check return value of resolve_refdup before using hash
2 parents c8c3321 + 57e0ef0 commit a207ad7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ static void am_abort(struct am_state *state)
21482148
am_rerere_clear();
21492149

21502150
curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
2151-
has_curr_head = !is_null_oid(&curr_head);
2151+
has_curr_head = curr_branch && !is_null_oid(&curr_head);
21522152
if (!has_curr_head)
21532153
hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
21542154

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@ static int switch_branches(const struct checkout_opts *opts,
835835
int flag, writeout_error = 0;
836836
memset(&old, 0, sizeof(old));
837837
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
838-
old.commit = lookup_commit_reference_gently(rev.hash, 1);
838+
if (old.path)
839+
old.commit = lookup_commit_reference_gently(rev.hash, 1);
839840
if (!(flag & REF_ISSYMREF))
840841
old.path = NULL;
841842

0 commit comments

Comments
 (0)