mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
checkout: 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. Found with t/t2011-checkout-invalid-head.sh --valgrind. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
49800c9407
commit
79e913c24a
|
@ -814,7 +814,8 @@ static int switch_branches(const struct checkout_opts *opts,
|
|||
int flag, writeout_error = 0;
|
||||
memset(&old, 0, sizeof(old));
|
||||
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
|
||||
old.commit = lookup_commit_reference_gently(rev.hash, 1);
|
||||
if (old.path)
|
||||
old.commit = lookup_commit_reference_gently(rev.hash, 1);
|
||||
if (!(flag & REF_ISSYMREF))
|
||||
old.path = NULL;
|
||||
|
||||
|
|
Loading…
Reference in a new issue