Skip to content

Commit 23424ea

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 745f681 commit 23424ea

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

t/t5318-commit-graph.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,47 @@ test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
585585
test_cmp expect actual
586586
'
587587

588+
test_expect_failure 'corrupt commit-graph write (broken parent)' '
589+
rm -rf repo &&
590+
git init repo &&
591+
(
592+
cd repo &&
593+
empty="$(git mktree </dev/null)" &&
594+
cat >broken <<-EOF &&
595+
tree $empty
596+
parent 0000000000000000000000000000000000000000
597+
author whatever <[email protected]> 1234 -0000
598+
committer whatever <[email protected]> 1234 -0000
599+
600+
broken commit
601+
EOF
602+
broken="$(git hash-object -w -t commit --literally broken)" &&
603+
git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
604+
test_must_fail git commit-graph write --stdin-commits \
605+
<good 2>test_err &&
606+
test_i18ngrep "unable to parse commit" test_err
607+
)
608+
'
609+
610+
test_expect_failure 'corrupt commit-graph write (missing tree)' '
611+
rm -rf repo &&
612+
git init repo &&
613+
(
614+
cd repo &&
615+
tree="$(git mktree </dev/null)" &&
616+
cat >broken <<-EOF &&
617+
parent 0000000000000000000000000000000000000000
618+
author whatever <[email protected]> 1234 -0000
619+
committer whatever <[email protected]> 1234 -0000
620+
621+
broken commit
622+
EOF
623+
broken="$(git hash-object -w -t commit --literally broken)" &&
624+
git commit-tree -p "$broken" -m "good" "$tree" >good &&
625+
test_must_fail git commit-graph write --stdin-commits \
626+
<good 2>test_err &&
627+
test_i18ngrep "unable to get tree for" test_err
628+
)
629+
'
630+
588631
test_done

0 commit comments

Comments
 (0)