t1450: add tests for NUL in headers of commits and tags
Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Jeff King <peff@peff.net>
René Scharfe committed
Nov 19, 2015 at 17:20 UTC
80c7f5a011416f4893c8e395bbf9f841a6dd624e
1 file changed
+32
t/t1450-fsck.sh
+32
@@ -176,6 +176,18 @@ test_expect_success 'integer overflow in timestamps is reported' '
176
grep "error in commit $new.*integer overflow" out
177
'
178
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
+
191
test_expect_success 'malformatted tree object' '
192
test_when_finished "git update-ref -d refs/tags/wrong" &&
193
test_when_finished "remove_object \$T" &&
@@ -276,6 +288,26 @@ test_expect_success 'tag with bad tagger' '
288
grep "error in tag .*: invalid author/committer" out
289
'
290
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 <tagger@example.com> 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
+
311
test_expect_success 'cleaned up' '
312
git fsck >actual 2>&1 &&
313
test_cmp empty actual