summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2019-09-05 22:04:57 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-09-09 17:55:59 (GMT)
commit806278dead57766bf000af62dcb8892ee3a24956 (patch)
treeb8b3c92ff86935c84553f5f1d035d881df65cac6 /commit.c
parent16749b8dd2cd2d3ab693ac7ebe110e57cf054005 (diff)
downloadgit-806278dead57766bf000af62dcb8892ee3a24956.zip
git-806278dead57766bf000af62dcb8892ee3a24956.tar.gz
git-806278dead57766bf000af62dcb8892ee3a24956.tar.bz2
commit-graph.c: handle corrupt/missing trees
Apply similar treatment as in the previous commit to handle an unchecked call to 'get_commit_tree_oid()'. Previously, a NULL return value from this function would be immediately dereferenced with '->hash', and then cause a segfault. Before dereferencing to access the 'hash' member, check the return value of 'get_commit_tree_oid()' to make sure that it is not NULL. To make this check correct, a related change is also needed in 'commit.c', which is to check the return value of 'get_commit_tree' before taking its address. If 'get_commit_tree' returns NULL, we encounter an undefined behavior when taking the address of the return value of 'get_commit_tree' and then taking '->object.oid'. (On my system, this is memory address 0x8, which is obviously wrong). Fix this by making sure that 'get_commit_tree' returns something non-NULL before digging through a structure that is not there, thus preventing a segfault down the line in the commit graph code. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/commit.c b/commit.c
index a98de16..fab22cb 100644
--- a/commit.c
+++ b/commit.c
@@ -358,7 +358,8 @@ struct tree *repo_get_commit_tree(struct repository *r,
struct object_id *get_commit_tree_oid(const struct commit *commit)
{
- return &get_commit_tree(commit)->object.oid;
+ struct tree *tree = get_commit_tree(commit);
+ return tree ? &tree->object.oid : NULL;
}
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)