Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2009 by Denys Vlasenko |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 4 | |
| 5 | . ./testing.sh |
| 6 | |
Dan Fandrich | 775965d | 2010-08-10 23:33:57 -0700 | [diff] [blame] | 7 | unset LANG |
| 8 | unset LANGUAGE |
| 9 | unset LC_COLLATE |
| 10 | unset LC_ALL |
| 11 | umask 022 |
| 12 | |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 13 | # testing "test name" "script" "expected result" "file input" "stdin" |
| 14 | |
Denys Vlasenko | 0545e3b | 2013-11-19 17:17:48 +0100 | [diff] [blame] | 15 | testing "Empty file is not a tarball" '\ |
| 16 | tar xvf - 2>&1; echo $? |
| 17 | ' "\ |
| 18 | tar: short read |
| 19 | 1 |
| 20 | " \ |
| 21 | "" "" |
| 22 | SKIP= |
| 23 | |
Denys Vlasenko | 0ad872b | 2016-06-20 01:40:19 +0200 | [diff] [blame] | 24 | optional FEATURE_SEAMLESS_GZ GUNZIP |
Denys Vlasenko | 198b02f | 2013-12-31 23:22:36 +0100 | [diff] [blame] | 25 | # In NOMMU case, "invalid magic" message comes from gunzip child process. |
| 26 | # Otherwise, it comes from tar. |
| 27 | # Need to fix output up to avoid false positive. |
Denys Vlasenko | dd1d8ab | 2013-11-19 16:56:26 +0100 | [diff] [blame] | 28 | testing "Empty file is not a tarball.tar.gz" '\ |
Denys Vlasenko | 198b02f | 2013-12-31 23:22:36 +0100 | [diff] [blame] | 29 | { tar xvzf - 2>&1; echo $?; } | grep -Fv "invalid magic" |
Denys Vlasenko | 1cbc642 | 2013-11-19 14:52:02 +0100 | [diff] [blame] | 30 | ' "\ |
Denys Vlasenko | 1cbc642 | 2013-11-19 14:52:02 +0100 | [diff] [blame] | 31 | tar: short read |
| 32 | 1 |
| 33 | " \ |
| 34 | "" "" |
| 35 | SKIP= |
| 36 | |
Denys Vlasenko | 0545e3b | 2013-11-19 17:17:48 +0100 | [diff] [blame] | 37 | testing "Two zeroed blocks is a ('truncated') empty tarball" '\ |
Denys Vlasenko | 7625811 | 2013-12-31 23:25:46 +0100 | [diff] [blame] | 38 | dd if=/dev/zero bs=512 count=2 2>/dev/null | tar xvf - 2>&1; echo $? |
Denys Vlasenko | 0545e3b | 2013-11-19 17:17:48 +0100 | [diff] [blame] | 39 | ' "\ |
| 40 | 0 |
| 41 | " \ |
| 42 | "" "" |
| 43 | SKIP= |
| 44 | |
| 45 | testing "Twenty zeroed blocks is an empty tarball" '\ |
| 46 | dd if=/dev/zero bs=512 count=20 2>/dev/null | tar xvf - 2>&1; echo $? |
| 47 | ' "\ |
| 48 | 0 |
| 49 | " \ |
| 50 | "" "" |
| 51 | SKIP= |
| 52 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 53 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 54 | # "tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input": |
| 55 | # GNU tar 1.26 records as hardlinks: |
| 56 | # input_hard2 -> input_hard1 |
| 57 | # input_hard1 -> input_hard1 (!!!) |
| 58 | # input_dir/file -> input_dir/file |
| 59 | # input -> input |
| 60 | # As of 1.24.0, we don't record last two: for them, nlink==1 |
| 61 | # and we check for "hardlink"ness only files with nlink!=1 |
| 62 | # We also don't use "hrw-r--r--" notation for hardlinks in "tar tv" listing. |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 63 | optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 64 | testing "tar hardlinks and repeated files" '\ |
Denys Vlasenko | 425ad9c | 2009-12-16 22:46:01 +0100 | [diff] [blame] | 65 | >input_hard1 |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 66 | ln input_hard1 input_hard2 |
| 67 | mkdir input_dir |
| 68 | >input_dir/file |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 69 | chmod -R 644 * |
| 70 | chmod 755 input_dir |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 71 | tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 72 | tar tvf test.tar | sed "s/.*[0-9] input/input/" |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 73 | rm -rf input_dir |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 74 | tar xf test.tar 2>&1 |
| 75 | echo Ok: $? |
| 76 | ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
| 77 | ' "\ |
Denys Vlasenko | 425ad9c | 2009-12-16 22:46:01 +0100 | [diff] [blame] | 78 | input |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 79 | input_dir/ |
| 80 | input_dir/file |
| 81 | input_hard1 |
| 82 | input_hard2 -> input_hard1 |
| 83 | input_hard1 -> input_hard1 |
| 84 | input_dir/ |
| 85 | input_dir/file |
| 86 | input |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 87 | Ok: 0 |
| 88 | -rw-r--r-- input_dir/file |
| 89 | drwxr-xr-x input_dir |
| 90 | -rw-r--r-- input_hard1 |
| 91 | -rw-r--r-- input_hard2 |
| 92 | " \ |
| 93 | "" "" |
Denys Vlasenko | e3d90a9 | 2010-05-10 05:53:16 +0200 | [diff] [blame] | 94 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 95 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 96 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 97 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 98 | optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 99 | testing "tar hardlinks mode" '\ |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 100 | >input_hard1 |
| 101 | chmod 741 input_hard1 |
| 102 | ln input_hard1 input_hard2 |
| 103 | mkdir input_dir |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 104 | ln input_hard1 input_dir |
| 105 | ln input_hard2 input_dir |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 106 | chmod 550 input_dir |
Denys Vlasenko | 0d7cb4c | 2010-09-03 17:22:56 +0200 | [diff] [blame] | 107 | # On some filesystems, input_dir/input_hard2 is returned by readdir |
| 108 | # BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*": |
| 109 | tar cf test.tar input_dir/input_hard* input_hard* |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 110 | tar tvf test.tar | sed "s/.*[0-9] input/input/" |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 111 | chmod 770 input_dir |
| 112 | rm -rf input_* |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 113 | tar xf test.tar 2>&1 |
| 114 | echo Ok: $? |
Denys Vlasenko | 0d7cb4c | 2010-09-03 17:22:56 +0200 | [diff] [blame] | 115 | ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 116 | ' "\ |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 117 | input_dir/input_hard1 |
| 118 | input_dir/input_hard2 -> input_dir/input_hard1 |
| 119 | input_hard1 -> input_dir/input_hard1 |
| 120 | input_hard2 -> input_dir/input_hard1 |
| 121 | Ok: 0 |
| 122 | -rwxr----x input_dir/input_hard1 |
| 123 | -rwxr----x input_dir/input_hard2 |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 124 | -rwxr----x input_hard1 |
| 125 | -rwxr----x input_hard2 |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 126 | " \ |
| 127 | "" "" |
Denys Vlasenko | e3d90a9 | 2010-05-10 05:53:16 +0200 | [diff] [blame] | 128 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 129 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 130 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 131 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 132 | optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 133 | testing "tar symlinks mode" '\ |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 134 | >input_file |
| 135 | chmod 741 input_file |
| 136 | ln -s input_file input_soft |
| 137 | mkdir input_dir |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 138 | ln input_file input_dir |
| 139 | ln input_soft input_dir |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 140 | chmod 550 input_dir |
Dan Fandrich | 80d80ba | 2010-09-11 00:28:50 -0700 | [diff] [blame] | 141 | tar cf test.tar input_dir/* input_[fs]* |
Denys Vlasenko | e82cf33 | 2010-05-12 15:59:32 +0200 | [diff] [blame] | 142 | tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 143 | chmod 770 input_dir |
| 144 | rm -rf input_* |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 145 | tar xf test.tar 2>&1 |
| 146 | echo Ok: $? |
Dan Fandrich | 80d80ba | 2010-09-11 00:28:50 -0700 | [diff] [blame] | 147 | ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 148 | ' "\ |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 149 | input_dir/input_file |
| 150 | input_dir/input_soft -> input_file |
| 151 | input_file -> input_dir/input_file |
| 152 | input_soft -> input_dir/input_soft |
| 153 | Ok: 0 |
| 154 | -rwxr----x input_dir/input_file |
| 155 | lrwxrwxrwx input_file |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 156 | -rwxr----x input_file |
| 157 | lrwxrwxrwx input_file |
| 158 | " \ |
| 159 | "" "" |
Denys Vlasenko | e3d90a9 | 2010-05-10 05:53:16 +0200 | [diff] [blame] | 160 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 161 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 162 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 163 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | da13824 | 2010-05-11 12:02:48 +0200 | [diff] [blame] | 164 | optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS |
Denys Vlasenko | 8a936cf | 2009-12-16 23:18:59 +0100 | [diff] [blame] | 165 | testing "tar --overwrite" "\ |
Denys Vlasenko | 8a936cf | 2009-12-16 23:18:59 +0100 | [diff] [blame] | 166 | ln input input_hard |
| 167 | tar cf test.tar input_hard |
| 168 | echo WRONG >input |
| 169 | # --overwrite opens 'input_hard' without unlinking, |
| 170 | # thus 'input_hard' still linked to 'input' and we write 'Ok' into it |
| 171 | tar xf test.tar --overwrite 2>&1 && cat input |
| 172 | " "\ |
| 173 | Ok |
| 174 | " \ |
| 175 | "Ok\n" "" |
Chris Metcalf | 208d35d | 2010-04-02 09:57:27 +0200 | [diff] [blame] | 176 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 177 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | 8a936cf | 2009-12-16 23:18:59 +0100 | [diff] [blame] | 178 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 179 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Dan Fandrich | 80d80ba | 2010-09-11 00:28:50 -0700 | [diff] [blame] | 180 | test x"$SKIP_KNOWN_BUGS" = x"" && { |
Dan Fandrich | 8d789e4 | 2010-09-05 16:16:46 +0200 | [diff] [blame] | 181 | # Needs to be run under non-root for meaningful test |
| 182 | optional FEATURE_TAR_CREATE |
| 183 | testing "tar writing into read-only dir" '\ |
Dan Fandrich | 8d789e4 | 2010-09-05 16:16:46 +0200 | [diff] [blame] | 184 | mkdir input_dir |
| 185 | >input_dir/input_file |
| 186 | chmod 550 input_dir |
| 187 | tar cf test.tar input_dir |
| 188 | tar tvf test.tar | sed "s/.*[0-9] input/input/" |
| 189 | chmod 770 input_dir |
| 190 | rm -rf input_* |
| 191 | tar xf test.tar 2>&1 |
| 192 | echo Ok: $? |
| 193 | ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
| 194 | chmod 770 input_dir |
| 195 | ' "\ |
| 196 | input_dir/ |
| 197 | input_dir/input_file |
| 198 | Ok: 0 |
| 199 | -rw-r--r-- input_dir/input_file |
| 200 | dr-xr-x--- input_dir |
| 201 | " \ |
| 202 | "" "" |
| 203 | SKIP= |
Dan Fandrich | 80d80ba | 2010-09-11 00:28:50 -0700 | [diff] [blame] | 204 | } |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 205 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Dan Fandrich | 80d80ba | 2010-09-11 00:28:50 -0700 | [diff] [blame] | 206 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 207 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | b8ab4b0 | 2011-02-06 20:02:15 +0100 | [diff] [blame] | 208 | # Had a bug where on extract autodetect first "switched off" -z |
Denys Vlasenko | aef441c | 2011-02-06 20:01:11 +0100 | [diff] [blame] | 209 | # and then failed to recognize .tgz extension |
Denys Vlasenko | ecf25cb | 2016-06-20 11:04:04 +0200 | [diff] [blame] | 210 | optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ GUNZIP |
Denys Vlasenko | aef441c | 2011-02-06 20:01:11 +0100 | [diff] [blame] | 211 | testing "tar extract tgz" "\ |
| 212 | dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null |
| 213 | tar -czf F0.tgz F0 |
| 214 | rm F0 |
| 215 | tar -xzvf F0.tgz && echo Ok |
| 216 | rm F0 || echo BAD |
| 217 | " "\ |
| 218 | F0 |
| 219 | Ok |
| 220 | " \ |
| 221 | "" "" |
Denys Vlasenko | b47b3ce | 2011-08-10 00:51:29 +0200 | [diff] [blame] | 222 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 223 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | aef441c | 2011-02-06 20:01:11 +0100 | [diff] [blame] | 224 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 225 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | bb8d7db | 2012-03-06 16:57:01 +0100 | [diff] [blame] | 226 | # Do we detect XZ-compressed data (even w/o .tar.xz or txz extension)? |
| 227 | # (the uuencoded hello_world.txz contains one empty file named "hello_world") |
| 228 | optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ |
| 229 | testing "tar extract txz" "\ |
| 230 | uudecode -o input && tar tf input && echo Ok |
| 231 | " "\ |
| 232 | hello_world |
| 233 | Ok |
| 234 | " \ |
| 235 | "" "\ |
| 236 | begin-base64 644 hello_world.txz |
| 237 | /Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ |
| 238 | SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2 |
| 239 | Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA |
| 240 | AAAEWVo= |
| 241 | ==== |
| 242 | " |
| 243 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 244 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | bb8d7db | 2012-03-06 16:57:01 +0100 | [diff] [blame] | 245 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 246 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | 5e29e26 | 2011-03-01 17:21:07 +0100 | [diff] [blame] | 247 | # On extract, everything up to and including last ".." component is stripped |
Denys Vlasenko | b47b3ce | 2011-08-10 00:51:29 +0200 | [diff] [blame] | 248 | optional FEATURE_TAR_CREATE |
Denys Vlasenko | 5e29e26 | 2011-03-01 17:21:07 +0100 | [diff] [blame] | 249 | testing "tar strips /../ on extract" "\ |
| 250 | rm -rf input_* test.tar 2>/dev/null |
| 251 | mkdir input_dir |
| 252 | echo Ok >input_dir/file |
| 253 | tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1 |
| 254 | rm -rf input_* 2>/dev/null |
| 255 | tar -vxf test.tar 2>&1 |
| 256 | cat input_dir/file 2>&1 |
| 257 | " "\ |
Denys Vlasenko | b80acf5 | 2011-03-02 01:21:02 +0100 | [diff] [blame] | 258 | tar: removing leading './../tar.tempdir/input_dir/../' from member names |
Denys Vlasenko | 5e29e26 | 2011-03-01 17:21:07 +0100 | [diff] [blame] | 259 | input_dir/ |
| 260 | input_dir/file |
| 261 | Ok |
| 262 | " \ |
| 263 | "" "" |
Denys Vlasenko | b47b3ce | 2011-08-10 00:51:29 +0200 | [diff] [blame] | 264 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 265 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | 5e29e26 | 2011-03-01 17:21:07 +0100 | [diff] [blame] | 266 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 267 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 268 | # attack.tar.bz2 has symlink pointing to a system file |
| 269 | # followed by a regular file with the same name |
| 270 | # containing "root::0:0::/root:/bin/sh": |
| 271 | # lrwxrwxrwx root/root passwd -> /tmp/passwd |
| 272 | # -rw-r--r-- root/root passwd |
| 273 | # naive tar implementation may end up creating the symlink |
| 274 | # and then writing into it. |
| 275 | # The correct implementation unlinks target before |
| 276 | # creating the second file. |
| 277 | # We test that /tmp/passwd remains empty: |
Denys Vlasenko | bb0bf28 | 2016-06-19 21:54:04 +0200 | [diff] [blame] | 278 | optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2 |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 279 | testing "tar does not extract into symlinks" "\ |
| 280 | >>/tmp/passwd && uudecode -o input && tar xf input 2>&1 && rm passwd; cat /tmp/passwd; echo \$? |
| 281 | " "\ |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 282 | tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 283 | 0 |
| 284 | " \ |
| 285 | "" "\ |
| 286 | begin-base64 644 attack.tar.bz2 |
| 287 | QlpoOTFBWSZTWRVn/bIAAKt7hMqwAEBAAP2QAhB0Y96AAACACCAAlISgpqe0 |
| 288 | po0DIaDynqAkpDRP1ANAhiYNSPR8VchKhAz0AK59+DA6FcMKBggOARIJdVHL |
| 289 | DGllrjs20ATUgR1HmccBX3EhoMnpMJaNyggmxgLDMz54lBnBTJO/1L1lbMS4 |
| 290 | l4/V8LDoe90yiWJhOJvIypgEfxdyRThQkBVn/bI= |
| 291 | ==== |
| 292 | " |
| 293 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 294 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
| 295 | |
| 296 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 297 | # And same with -k |
Denys Vlasenko | bb0bf28 | 2016-06-19 21:54:04 +0200 | [diff] [blame] | 298 | optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2 |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 299 | testing "tar -k does not extract into symlinks" "\ |
| 300 | >>/tmp/passwd && uudecode -o input && tar xf input -k 2>&1 && rm passwd; cat /tmp/passwd; echo \$? |
| 301 | " "\ |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 302 | tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 303 | 0 |
| 304 | " \ |
| 305 | "" "\ |
| 306 | begin-base64 644 attack.tar.bz2 |
| 307 | QlpoOTFBWSZTWRVn/bIAAKt7hMqwAEBAAP2QAhB0Y96AAACACCAAlISgpqe0 |
| 308 | po0DIaDynqAkpDRP1ANAhiYNSPR8VchKhAz0AK59+DA6FcMKBggOARIJdVHL |
| 309 | DGllrjs20ATUgR1HmccBX3EhoMnpMJaNyggmxgLDMz54lBnBTJO/1L1lbMS4 |
| 310 | l4/V8LDoe90yiWJhOJvIypgEfxdyRThQkBVn/bI= |
| 311 | ==== |
| 312 | " |
| 313 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 314 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | a960748 | 2015-10-22 16:37:01 +0200 | [diff] [blame] | 315 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 316 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
Denys Vlasenko | df25df7 | 2016-12-12 14:33:53 +0100 | [diff] [blame] | 317 | optional UNICODE_SUPPORT FEATURE_TAR_GNU_EXTENSIONS FEATURE_SEAMLESS_BZ2 FEATURE_TAR_AUTODETECT |
Denys Vlasenko | 9655f95 | 2016-11-11 17:56:45 +0100 | [diff] [blame] | 318 | testing "Pax-encoded UTF8 names and symlinks" '\ |
| 319 | tar xvf ../tar.utf8.tar.bz2 2>&1; echo $? |
| 320 | export LANG=en_US.UTF-8 |
Denys Vlasenko | 76de325 | 2016-12-12 19:17:12 +0100 | [diff] [blame] | 321 | ls -l etc/ssl/certs/* | sed "s:.*etc/:etc/:" | sort |
Denys Vlasenko | 9655f95 | 2016-11-11 17:56:45 +0100 | [diff] [blame] | 322 | unset LANG |
| 323 | rm -rf etc usr |
| 324 | ' "\ |
| 325 | etc/ssl/certs/3b2716e5.0 |
| 326 | etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 327 | tar: skipping unsafe symlink to '/usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract |
Denys Vlasenko | 9655f95 | 2016-11-11 17:56:45 +0100 | [diff] [blame] | 328 | etc/ssl/certs/f80cc7f6.0 |
| 329 | usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt |
| 330 | 0 |
| 331 | etc/ssl/certs/3b2716e5.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem |
Denys Vlasenko | 9655f95 | 2016-11-11 17:56:45 +0100 | [diff] [blame] | 332 | etc/ssl/certs/f80cc7f6.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem |
| 333 | " \ |
| 334 | "" "" |
| 335 | SKIP= |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 336 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | 9655f95 | 2016-11-11 17:56:45 +0100 | [diff] [blame] | 337 | |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 338 | mkdir tar.tempdir && cd tar.tempdir || exit 1 |
| 339 | optional FEATURE_SEAMLESS_BZ2 FEATURE_TAR_AUTODETECT |
| 340 | testing "Symlink attack: create symlink and then write through it" '\ |
| 341 | exec 2>&1 |
| 342 | uudecode -o input && tar xvf input; echo $? |
| 343 | ls /tmp/bb_test_evilfile |
| 344 | ls bb_test_evilfile |
| 345 | ls symlink/bb_test_evilfile |
| 346 | ' "\ |
| 347 | anything.txt |
| 348 | symlink |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 349 | tar: skipping unsafe symlink to '/tmp' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 350 | symlink/bb_test_evilfile |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 351 | 0 |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 352 | ls: /tmp/bb_test_evilfile: No such file or directory |
| 353 | ls: bb_test_evilfile: No such file or directory |
| 354 | symlink/bb_test_evilfile |
| 355 | " \ |
| 356 | "" "\ |
| 357 | begin-base64 644 tar_symlink_attack.tar.bz2 |
| 358 | QlpoOTFBWSZTWZgs7bQAALT/hMmQAFBAAf+AEMAGJPPv32AAAIAIMAC5thlR |
| 359 | omAjAmCMADQT1BqNE0AEwAAjAEwElTKeo9NTR6h6gaeoA0DQNLVdwZZ5iNTk |
| 360 | AQwCAV6S00QFJYhrlfFkVCEDEGtgNVqYrI0uK3ggnt30gqk4e1TTQm5QIAKa |
| 361 | SJqzRGSFLMmOloHSAcvLiFxxRiQtQZF+qPxbo173ZDISOAoNoPN4PQPhBhKS |
| 362 | n8fYaKlioCTzL2oXYczyUUIP4u5IpwoSEwWdtoA= |
| 363 | ==== |
| 364 | " |
| 365 | SKIP= |
| 366 | cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 367 | |
| 368 | exit $FAILCOUNT |