3 test_description
='paths written by git-apply cannot escape the working tree'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # tests will try to write to ../foo, and we do not
9 # want them to escape the trash directory when they
11 test_expect_success
'bump git repo one level down' '
18 # $2 = current path to file (if different)
24 index 0000000..53c74cd
33 echo evil
>"${2:-$1}" &&
36 deleted file mode 100644
37 index 53c74cd..0000000
46 # $2 = content of symlink
52 index 0000000..$(printf "%s" "$2" | git hash-object --stdin)
57 \ No newline at end of file
61 test_expect_success
'cannot create file containing ..' '
62 mkpatch_add ../foo >patch &&
63 test_must_fail git apply patch &&
64 test_path_is_missing ../foo
67 test_expect_success
'can create file containing .. with --unsafe-paths' '
68 mkpatch_add ../foo >patch &&
69 git apply --unsafe-paths patch &&
70 test_path_is_file ../foo
73 test_expect_success
'cannot create file containing .. (index)' '
74 mkpatch_add ../foo >patch &&
75 test_must_fail git apply --index patch &&
76 test_path_is_missing ../foo
79 test_expect_success
'cannot create file containing .. with --unsafe-paths (index)' '
80 mkpatch_add ../foo >patch &&
81 test_must_fail git apply --index --unsafe-paths patch &&
82 test_path_is_missing ../foo
85 test_expect_success
'cannot delete file containing ..' '
86 mkpatch_del ../foo >patch &&
87 test_must_fail git apply patch &&
88 test_path_is_file ../foo
91 test_expect_success
'can delete file containing .. with --unsafe-paths' '
92 mkpatch_del ../foo >patch &&
93 git apply --unsafe-paths patch &&
94 test_path_is_missing ../foo
97 test_expect_success
'cannot delete file containing .. (index)' '
98 mkpatch_del ../foo >patch &&
99 test_must_fail git apply --index patch &&
100 test_path_is_file ../foo
103 test_expect_success SYMLINKS
'symlink escape via ..' '
105 mkpatch_symlink tmp .. &&
106 mkpatch_add tmp/foo ../foo
108 test_must_fail git apply patch &&
109 test_path_is_missing tmp &&
110 test_path_is_missing ../foo
113 test_expect_success SYMLINKS
'symlink escape via .. (index)' '
115 mkpatch_symlink tmp .. &&
116 mkpatch_add tmp/foo ../foo
118 test_must_fail git apply --index patch &&
119 test_path_is_missing tmp &&
120 test_path_is_missing ../foo
123 test_expect_success SYMLINKS
'symlink escape via absolute path' '
125 mkpatch_symlink tmp "$(pwd)" &&
126 mkpatch_add tmp/foo ../foo
128 test_must_fail git apply patch &&
129 test_path_is_missing tmp &&
130 test_path_is_missing ../foo
133 test_expect_success SYMLINKS
'symlink escape via absolute path (index)' '
135 mkpatch_symlink tmp "$(pwd)" &&
136 mkpatch_add tmp/foo ../foo
138 test_must_fail git apply --index patch &&
139 test_path_is_missing tmp &&
140 test_path_is_missing ../foo