1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 12:59:41 +01:00
git/t/t1601-index-bogus.sh
Patrick Steinhardt d1c53f6703 read-cache: fix leaking hashfile when writing index fails
In `do_write_index()`, we use a `struct hashfile` to write the index
with a trailer hash. In case the write fails though, we never clean up
the allocated `hashfile` state and thus leak memory.

Refactor the code to have a common exit path where we can free this and
other allocated memory. While at it, refactor our use of `strbuf`s such
that we reuse the same buffer to avoid some unneeded allocations.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-08-14 10:07:58 -07:00

24 lines
554 B
Bash
Executable file

#!/bin/sh
test_description='test handling of bogus index entries'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'create tree with null sha1' '
tree=$(printf "160000 commit $ZERO_OID\\tbroken\\n" | git mktree)
'
test_expect_success 'read-tree refuses to read null sha1' '
test_must_fail git read-tree $tree
'
test_expect_success 'GIT_ALLOW_NULL_SHA1 overrides refusal' '
GIT_ALLOW_NULL_SHA1=1 git read-tree $tree
'
test_expect_success 'git write-tree refuses to write null sha1' '
test_must_fail git write-tree
'
test_done