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