3 test_description
='git am with corrupt input'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 make_mbox_with_nul
() {
15 subject
) q_nul_in_subject
='=00' ;;
16 body
) q_nul_in_body
='=00' ;;
21 From ec7364544f690c560304f5a5de9428ea3b978b26 Mon Sep 17 00:00:00 2001
22 From: A U Thor <author@example.com>
23 Date: Sun, 19 Apr 2020 13:42:07 +0700
24 Subject: [PATCH] =?ISO-8859-1?q?=C4=CB${q_nul_in_subject}=D1=CF=D6?=
26 Content-Type: text/plain; charset=ISO-8859-1
27 Content-Transfer-Encoding: quoted-printable
29 abc${q_nul_in_body}def
31 diff --git a/afile b/afile
33 index 0000000000..e69de29bb2
39 test_expect_success setup
'
40 # Note the missing "+++" line:
41 cat >bad-patch.diff <<-\EOF &&
42 From: A U Thor <au.thor@example.com>
44 index 7898192..6178079 100644
57 # This used to fail before, too, but with a different diagnostic.
58 # fatal: unable to write file '(null)' mode 100644: Bad address
59 # Also, it had the unwanted side-effect of deleting f.
60 test_expect_success
'try to apply corrupted patch' '
61 test_when_finished "git am --abort" &&
62 test_must_fail git -c advice.amWorkDir=false am bad-patch.diff 2>actual &&
63 echo "error: git diff header lacks filename information (line 4)" >expected &&
64 test_path_is_file f &&
65 test_cmp expected actual
68 test_expect_success
"NUL in commit message's body" '
69 test_when_finished "git am --abort" &&
70 make_mbox_with_nul body >body.patch &&
71 test_must_fail git am body.patch 2>err &&
72 grep "a NUL byte in commit log message not allowed" err
75 test_expect_success
"NUL in commit message's header" "
76 test_when_finished 'git am --abort' &&
77 make_mbox_with_nul subject >subject.patch &&
78 test_must_fail git mailinfo msg patch <subject.patch 2>err &&
79 grep \"a NUL byte in 'Subject' is not allowed\" err &&
80 test_must_fail git am subject.patch 2>err &&
81 grep \"a NUL byte in 'Subject' is not allowed\" err