Skip to content

Commit 80c7f5a

Browse files
rscharfepeff
authored andcommitted
t1450: add tests for NUL in headers of commits and tags
Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 0c83680 commit 80c7f5a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

t/t1450-fsck.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ test_expect_success 'integer overflow in timestamps is reported' '
176176
grep "error in commit $new.*integer overflow" out
177177
'
178178

179+
test_expect_success 'commit with NUL in header' '
180+
git cat-file commit HEAD >basis &&
181+
sed "s/author ./author Q/" <basis | q_to_nul >commit-NUL-header &&
182+
new=$(git hash-object -t commit -w --stdin <commit-NUL-header) &&
183+
test_when_finished "remove_object $new" &&
184+
git update-ref refs/heads/bogus "$new" &&
185+
test_when_finished "git update-ref -d refs/heads/bogus" &&
186+
test_must_fail git fsck 2>out &&
187+
cat out &&
188+
grep "error in commit $new.*unterminated header: NUL at offset" out
189+
'
190+
179191
test_expect_success 'malformatted tree object' '
180192
test_when_finished "git update-ref -d refs/tags/wrong" &&
181193
test_when_finished "remove_object \$T" &&
@@ -276,6 +288,26 @@ test_expect_success 'tag with bad tagger' '
276288
grep "error in tag .*: invalid author/committer" out
277289
'
278290

291+
test_expect_failure 'tag with NUL in header' '
292+
sha=$(git rev-parse HEAD) &&
293+
q_to_nul >tag-NUL-header <<-EOF &&
294+
object $sha
295+
type commit
296+
tag contains-Q-in-header
297+
tagger T A Gger <[email protected]> 1234567890 -0000
298+
299+
This is an invalid tag.
300+
EOF
301+
302+
tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) &&
303+
test_when_finished "remove_object $tag" &&
304+
echo $tag >.git/refs/tags/wrong &&
305+
test_when_finished "git update-ref -d refs/tags/wrong" &&
306+
test_must_fail git fsck --tags 2>out &&
307+
cat out &&
308+
grep "error in tag $tag.*unterminated header: NUL at offset" out
309+
'
310+
279311
test_expect_success 'cleaned up' '
280312
git fsck >actual 2>&1 &&
281313
test_cmp empty actual

0 commit comments

Comments
 (0)