From: Taylor Blau Date: Thu, 5 Sep 2019 22:04:53 +0000 (-0400) Subject: t/t5318: introduce failing 'git commit-graph write' tests X-Git-Tag: v2.24.0-rc0~69^2~2 X-Git-Url: http://git.bitbasher.net/?a=commitdiff_plain;h=23424ea7597fa17b96c82001b281a5d21f5b4874;p=git.git t/t5318: introduce failing 'git commit-graph write' tests When invoking 'git commit-graph' in a corrupt repository, one can cause a segfault when ancestral commits are corrupt in one way or another. This is due to two function calls in the 'commit-graph.c' code that may return NULL, but are not checked for NULL-ness before dereferencing. Before fixing the bug, introduce two failing tests that demonstrate the problem. The first test corrupts an ancestral commit's parent to point to a non-existent object. The second test instead corrupts an ancestral tree by removing the 'tree' information entirely from the commit. Both of these cases cause segfaults, each at different lines. Signed-off-by: Taylor Blau Acked-by: Derrick Stolee Signed-off-by: Junio C Hamano --- diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index ab3eccf0fa..c855f81930 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -585,4 +585,47 @@ test_expect_success 'get_commit_tree_in_graph works for non-the_repository' ' test_cmp expect actual ' +test_expect_failure 'corrupt commit-graph write (broken parent)' ' + rm -rf repo && + git init repo && + ( + cd repo && + empty="$(git mktree broken <<-EOF && + tree $empty + parent 0000000000000000000000000000000000000000 + author whatever 1234 -0000 + committer whatever 1234 -0000 + + broken commit + EOF + broken="$(git hash-object -w -t commit --literally broken)" && + git commit-tree -p "$broken" -m "good commit" "$empty" >good && + test_must_fail git commit-graph write --stdin-commits \ + test_err && + test_i18ngrep "unable to parse commit" test_err + ) +' + +test_expect_failure 'corrupt commit-graph write (missing tree)' ' + rm -rf repo && + git init repo && + ( + cd repo && + tree="$(git mktree broken <<-EOF && + parent 0000000000000000000000000000000000000000 + author whatever 1234 -0000 + committer whatever 1234 -0000 + + broken commit + EOF + broken="$(git hash-object -w -t commit --literally broken)" && + git commit-tree -p "$broken" -m "good" "$tree" >good && + test_must_fail git commit-graph write --stdin-commits \ + test_err && + test_i18ngrep "unable to get tree for" test_err + ) +' + test_done