diff options
author | Taylor Blau <me@ttaylorr.com> | 2019-09-05 18:04:57 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-09-09 10:55:59 -0700 |
commit | 806278dead57766bf000af62dcb8892ee3a24956 (patch) | |
tree | b8b3c92ff86935c84553f5f1d035d881df65cac6 /t | |
parent | commit-graph.c: handle commit parsing errors (diff) | |
download | tgif-806278dead57766bf000af62dcb8892ee3a24956.tar.xz |
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 't')
-rwxr-xr-x | t/t5318-commit-graph.sh | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index abde8d4e90..5d2d88b100 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -607,7 +607,7 @@ test_expect_success 'corrupt commit-graph write (broken parent)' ' ) ' -test_expect_failure 'corrupt commit-graph write (missing tree)' ' +test_expect_success 'corrupt commit-graph write (missing tree)' ' rm -rf repo && git init repo && ( |