summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-05-06 19:13:52 +0200
committerJunio C Hamano <gitster@pobox.com>2017-05-08 11:12:09 +0900
commit79e913c24aa37d0ede9ed9e8962a19634ae5129a (patch)
tree0ea3f3c69c978b7b07a5dc83dd8f4d8594a5e1a9
parent49800c940790cc7465d1b03e08d472ffd8684808 (diff)
downloadgit-79e913c24aa37d0ede9ed9e8962a19634ae5129a.tar.gz
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>
-rw-r--r--builtin/checkout.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 81f07c3ef2..5744499098 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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;