The eleventh batch
[git/gitster.git] / t / t4254-am-corrupt.sh
blobcb03522d02176fd601cecf25890458e79e25237c
1 #!/bin/sh
3 test_description='git am with corrupt input'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 if ! test_have_prereq ICONV
9 then
10 skip_all='skipping am encoding corruption tests; iconv not available'
11 test_done
14 make_mbox_with_nul () {
15 space=' '
16 q_nul_in_subject=
17 q_nul_in_body=
18 while test $# -ne 0
20 case "$1" in
21 subject) q_nul_in_subject='=00' ;;
22 body) q_nul_in_body='=00' ;;
23 esac &&
24 shift
25 done &&
26 cat <<-EOF
27 From ec7364544f690c560304f5a5de9428ea3b978b26 Mon Sep 17 00:00:00 2001
28 From: A U Thor <author@example.com>
29 Date: Sun, 19 Apr 2020 13:42:07 +0700
30 Subject: [PATCH] =?ISO-8859-1?q?=C4=CB${q_nul_in_subject}=D1=CF=D6?=
31 MIME-Version: 1.0
32 Content-Type: text/plain; charset=ISO-8859-1
33 Content-Transfer-Encoding: quoted-printable
35 abc${q_nul_in_body}def
36 ---
37 diff --git a/afile b/afile
38 new file mode 100644
39 index 0000000000..e69de29bb2
40 --$space
41 2.26.1
42 EOF
45 test_expect_success setup '
46 # Note the missing "+++" line:
47 cat >bad-patch.diff <<-\EOF &&
48 From: A U Thor <au.thor@example.com>
49 diff --git a/f b/f
50 index 7898192..6178079 100644
51 --- a/f
52 @@ -1 +1 @@
55 EOF
57 echo a >f &&
58 git add f &&
59 test_tick &&
60 git commit -m initial
63 # This used to fail before, too, but with a different diagnostic.
64 # fatal: unable to write file '(null)' mode 100644: Bad address
65 # Also, it had the unwanted side-effect of deleting f.
66 test_expect_success 'try to apply corrupted patch' '
67 test_when_finished "git am --abort" &&
68 test_must_fail git -c advice.amWorkDir=false -c advice.mergeConflict=false am bad-patch.diff 2>actual &&
69 echo "error: git diff header lacks filename information (line 4)" >expected &&
70 test_path_is_file f &&
71 test_cmp expected actual
74 test_expect_success "NUL in commit message's body" '
75 test_when_finished "git am --abort" &&
76 make_mbox_with_nul body >body.patch &&
77 test_must_fail git am body.patch 2>err &&
78 grep "a NUL byte in commit log message not allowed" err
81 test_expect_success "NUL in commit message's header" "
82 test_when_finished 'git am --abort' &&
83 make_mbox_with_nul subject >subject.patch &&
84 test_must_fail git mailinfo msg patch <subject.patch 2>err &&
85 grep \"a NUL byte in 'Subject' is not allowed\" err &&
86 test_must_fail git am subject.patch 2>err &&
87 grep \"a NUL byte in 'Subject' is not allowed\" err
90 test_done