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