3 test_description='paths written by git-apply cannot escape the working tree'
6 # tests will try to write to ../foo, and we do not
7 # want them to escape the trash directory when they
9 test_expect_success 'bump git repo one level down' '
16 # $2 = current path to file (if different)
22 index 0000000..53c74cd
31 echo evil >"${2:-$1}" &&
34 deleted file mode 100644
35 index 53c74cd..0000000
44 # $2 = content of symlink
50 index 0000000..$(printf "%s" "$2" | git hash-object --stdin)
55 \ No newline at end of file
59 test_expect_success 'cannot create file containing ..' '
60 mkpatch_add ../foo >patch &&
61 test_must_fail git apply patch &&
62 test_path_is_missing ../foo
65 test_expect_success 'can create file containing .. with --unsafe-paths' '
66 mkpatch_add ../foo >patch &&
67 git apply --unsafe-paths patch &&
68 test_path_is_file ../foo
71 test_expect_success 'cannot create file containing .. (index)' '
72 mkpatch_add ../foo >patch &&
73 test_must_fail git apply --index patch &&
74 test_path_is_missing ../foo
77 test_expect_success 'cannot create file containing .. with --unsafe-paths (index)' '
78 mkpatch_add ../foo >patch &&
79 test_must_fail git apply --index --unsafe-paths patch &&
80 test_path_is_missing ../foo
83 test_expect_success 'cannot delete file containing ..' '
84 mkpatch_del ../foo >patch &&
85 test_must_fail git apply patch &&
86 test_path_is_file ../foo
89 test_expect_success 'can delete file containing .. with --unsafe-paths' '
90 mkpatch_del ../foo >patch &&
91 git apply --unsafe-paths patch &&
92 test_path_is_missing ../foo
95 test_expect_success 'cannot delete file containing .. (index)' '
96 mkpatch_del ../foo >patch &&
97 test_must_fail git apply --index patch &&
98 test_path_is_file ../foo
101 test_expect_success SYMLINKS 'symlink escape via ..' '
103 mkpatch_symlink tmp .. &&
104 mkpatch_add tmp/foo ../foo
106 test_must_fail git apply patch &&
107 test_path_is_missing tmp &&
108 test_path_is_missing ../foo
111 test_expect_success SYMLINKS 'symlink escape via .. (index)' '
113 mkpatch_symlink tmp .. &&
114 mkpatch_add tmp/foo ../foo
116 test_must_fail git apply --index patch &&
117 test_path_is_missing tmp &&
118 test_path_is_missing ../foo
121 test_expect_success SYMLINKS 'symlink escape via absolute path' '
123 mkpatch_symlink tmp "$(pwd)" &&
124 mkpatch_add tmp/foo ../foo
126 test_must_fail git apply patch &&
127 test_path_is_missing tmp &&
128 test_path_is_missing ../foo
131 test_expect_success SYMLINKS 'symlink escape via absolute path (index)' '
133 mkpatch_symlink tmp "$(pwd)" &&
134 mkpatch_add tmp/foo ../foo
136 test_must_fail git apply --index patch &&
137 test_path_is_missing tmp &&
138 test_path_is_missing ../foo