]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4254-am-corrupt.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t4254-am-corrupt.sh
CommitLineData
2c93286a
JM
1#!/bin/sh
2
3test_description='git am with corrupt input'
b2e5d75d
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
2c93286a
JM
6. ./test-lib.sh
7
2a2ff603
ĐTCD
8make_mbox_with_nul () {
9 space=' '
10 q_nul_in_subject=
11 q_nul_in_body=
12 while test $# -ne 0
13 do
14 case "$1" in
15 subject) q_nul_in_subject='=00' ;;
16 body) q_nul_in_body='=00' ;;
17 esac &&
18 shift
19 done &&
20 cat <<-EOF
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?=
25 MIME-Version: 1.0
26 Content-Type: text/plain; charset=ISO-8859-1
27 Content-Transfer-Encoding: quoted-printable
28
29 abc${q_nul_in_body}def
30 ---
31 diff --git a/afile b/afile
32 new file mode 100644
33 index 0000000000..e69de29bb2
34 --$space
35 2.26.1
36 EOF
37}
38
2c93286a 39test_expect_success setup '
ddeaf7ef
SG
40 # Note the missing "+++" line:
41 cat >bad-patch.diff <<-\EOF &&
42 From: A U Thor <au.thor@example.com>
43 diff --git a/f b/f
44 index 7898192..6178079 100644
45 --- a/f
46 @@ -1 +1 @@
47 -a
48 +b
49 EOF
50
51 echo a >f &&
2c93286a
JM
52 git add f &&
53 test_tick &&
54 git commit -m initial
55'
56
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.
60test_expect_success 'try to apply corrupted patch' '
2ed282cc 61 test_when_finished "git am --abort" &&
37ce9735 62 test_must_fail git -c advice.amWorkDir=false -c advice.mergeConflict=false am bad-patch.diff 2>actual &&
5950851e 63 echo "error: git diff header lacks filename information (line 4)" >expected &&
ddeaf7ef 64 test_path_is_file f &&
1108cea7 65 test_cmp expected actual
2c93286a
JM
66'
67
2a2ff603
ĐTCD
68test_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
73'
74
39199974 75test_expect_success "NUL in commit message's header" "
2a2ff603
ĐTCD
76 test_when_finished 'git am --abort' &&
77 make_mbox_with_nul subject >subject.patch &&
39199974
ĐTCD
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
2a2ff603
ĐTCD
82"
83
2c93286a 84test_done