source: MondoRescue/branches/3.3/mindi-busybox/testsuite/tar.tests@ 3647

Last change on this file since 3647 was 3621, checked in by Bruno Cornec, 10 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

  • Property svn:executable set to *
File size: 7.7 KB
Line 
1#!/bin/sh
2# Copyright 2009 by Denys Vlasenko
3# Licensed under GPLv2, see file LICENSE in this source tree.
4
5. ./testing.sh
6
7unset LANG
8unset LANGUAGE
9unset LC_COLLATE
10unset LC_ALL
11umask 022
12
13rm -rf tar.tempdir 2>/dev/null
14mkdir tar.tempdir && cd tar.tempdir || exit 1
15
16# testing "test name" "script" "expected result" "file input" "stdin"
17
18testing "Empty file is not a tarball" '\
19tar xvf - 2>&1; echo $?
20' "\
21tar: short read
221
23" \
24"" ""
25SKIP=
26
27optional FEATURE_SEAMLESS_GZ GUNZIP
28# In NOMMU case, "invalid magic" message comes from gunzip child process.
29# Otherwise, it comes from tar.
30# Need to fix output up to avoid false positive.
31testing "Empty file is not a tarball.tar.gz" '\
32{ tar xvzf - 2>&1; echo $?; } | grep -Fv "invalid magic"
33' "\
34tar: short read
351
36" \
37"" ""
38SKIP=
39
40testing "Two zeroed blocks is a ('truncated') empty tarball" '\
41dd if=/dev/zero bs=512 count=2 2>/dev/null | tar xvf - 2>&1; echo $?
42' "\
430
44" \
45"" ""
46SKIP=
47
48testing "Twenty zeroed blocks is an empty tarball" '\
49dd if=/dev/zero bs=512 count=20 2>/dev/null | tar xvf - 2>&1; echo $?
50' "\
510
52" \
53"" ""
54SKIP=
55
56# "tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input":
57# GNU tar 1.26 records as hardlinks:
58# input_hard2 -> input_hard1
59# input_hard1 -> input_hard1 (!!!)
60# input_dir/file -> input_dir/file
61# input -> input
62# As of 1.24.0, we don't record last two: for them, nlink==1
63# and we check for "hardlink"ness only files with nlink!=1
64# We also don't use "hrw-r--r--" notation for hardlinks in "tar tv" listing.
65optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
66testing "tar hardlinks and repeated files" '\
67rm -rf input_* test.tar 2>/dev/null
68>input_hard1
69ln input_hard1 input_hard2
70mkdir input_dir
71>input_dir/file
72chmod -R 644 *
73chmod 755 input_dir
74tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
75tar tvf test.tar | sed "s/.*[0-9] input/input/"
76rm -rf input_dir
77tar xf test.tar 2>&1
78echo Ok: $?
79ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
80' "\
81input
82input_dir/
83input_dir/file
84input_hard1
85input_hard2 -> input_hard1
86input_hard1 -> input_hard1
87input_dir/
88input_dir/file
89input
90Ok: 0
91-rw-r--r-- input_dir/file
92drwxr-xr-x input_dir
93-rw-r--r-- input_hard1
94-rw-r--r-- input_hard2
95" \
96"" ""
97SKIP=
98
99optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
100testing "tar hardlinks mode" '\
101rm -rf input_* test.tar 2>/dev/null
102>input_hard1
103chmod 741 input_hard1
104ln input_hard1 input_hard2
105mkdir input_dir
106ln input_hard1 input_dir
107ln input_hard2 input_dir
108chmod 550 input_dir
109# On some filesystems, input_dir/input_hard2 is returned by readdir
110# BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*":
111tar cf test.tar input_dir/input_hard* input_hard*
112tar tvf test.tar | sed "s/.*[0-9] input/input/"
113chmod 770 input_dir
114rm -rf input_*
115tar xf test.tar 2>&1
116echo Ok: $?
117ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
118' "\
119input_dir/input_hard1
120input_dir/input_hard2 -> input_dir/input_hard1
121input_hard1 -> input_dir/input_hard1
122input_hard2 -> input_dir/input_hard1
123Ok: 0
124-rwxr----x input_dir/input_hard1
125-rwxr----x input_dir/input_hard2
126-rwxr----x input_hard1
127-rwxr----x input_hard2
128" \
129"" ""
130SKIP=
131
132optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
133testing "tar symlinks mode" '\
134rm -rf input_* test.tar 2>/dev/null
135>input_file
136chmod 741 input_file
137ln -s input_file input_soft
138mkdir input_dir
139ln input_file input_dir
140ln input_soft input_dir
141chmod 550 input_dir
142tar cf test.tar input_dir/* input_[fs]*
143tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
144chmod 770 input_dir
145rm -rf input_*
146tar xf test.tar 2>&1
147echo Ok: $?
148ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
149' "\
150input_dir/input_file
151input_dir/input_soft -> input_file
152input_file -> input_dir/input_file
153input_soft -> input_dir/input_soft
154Ok: 0
155-rwxr----x input_dir/input_file
156lrwxrwxrwx input_file
157-rwxr----x input_file
158lrwxrwxrwx input_file
159" \
160"" ""
161SKIP=
162
163optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
164testing "tar --overwrite" "\
165rm -rf input_* test.tar 2>/dev/null
166ln input input_hard
167tar cf test.tar input_hard
168echo WRONG >input
169# --overwrite opens 'input_hard' without unlinking,
170# thus 'input_hard' still linked to 'input' and we write 'Ok' into it
171tar xf test.tar --overwrite 2>&1 && cat input
172" "\
173Ok
174" \
175"Ok\n" ""
176SKIP=
177
178test x"$SKIP_KNOWN_BUGS" = x"" && {
179# Needs to be run under non-root for meaningful test
180optional FEATURE_TAR_CREATE
181testing "tar writing into read-only dir" '\
182rm -rf input_* test.tar 2>/dev/null
183mkdir input_dir
184>input_dir/input_file
185chmod 550 input_dir
186tar cf test.tar input_dir
187tar tvf test.tar | sed "s/.*[0-9] input/input/"
188chmod 770 input_dir
189rm -rf input_*
190tar xf test.tar 2>&1
191echo Ok: $?
192ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
193chmod 770 input_dir
194' "\
195input_dir/
196input_dir/input_file
197Ok: 0
198-rw-r--r-- input_dir/input_file
199dr-xr-x--- input_dir
200" \
201"" ""
202SKIP=
203}
204
205# Had a bug where on extract autodetect first "switched off" -z
206# and then failed to recognize .tgz extension
207optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ GUNZIP
208testing "tar extract tgz" "\
209dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
210tar -czf F0.tgz F0
211rm F0
212tar -xzvf F0.tgz && echo Ok
213rm F0 || echo BAD
214" "\
215F0
216Ok
217" \
218"" ""
219SKIP=
220
221# Do we detect XZ-compressed data (even w/o .tar.xz or txz extension)?
222# (the uuencoded hello_world.txz contains one empty file named "hello_world")
223optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ
224testing "tar extract txz" "\
225uudecode -o input && tar tf input && echo Ok
226" "\
227hello_world
228Ok
229" \
230"" "\
231begin-base64 644 hello_world.txz
232/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ
233SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2
234Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA
235AAAEWVo=
236====
237"
238SKIP=
239
240# On extract, everything up to and including last ".." component is stripped
241optional FEATURE_TAR_CREATE
242testing "tar strips /../ on extract" "\
243rm -rf input_* test.tar 2>/dev/null
244mkdir input_dir
245echo Ok >input_dir/file
246tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
247rm -rf input_* 2>/dev/null
248tar -vxf test.tar 2>&1
249cat input_dir/file 2>&1
250" "\
251tar: removing leading './../tar.tempdir/input_dir/../' from member names
252input_dir/
253input_dir/file
254Ok
255" \
256"" ""
257SKIP=
258
259# attack.tar.bz2 has symlink pointing to a system file
260# followed by a regular file with the same name
261# containing "root::0:0::/root:/bin/sh":
262# lrwxrwxrwx root/root passwd -> /tmp/passwd
263# -rw-r--r-- root/root passwd
264# naive tar implementation may end up creating the symlink
265# and then writing into it.
266# The correct implementation unlinks target before
267# creating the second file.
268# We test that /tmp/passwd remains empty:
269optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
270testing "tar does not extract into symlinks" "\
271>>/tmp/passwd && uudecode -o input && tar xf input 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
272" "\
2730
274" \
275"" "\
276begin-base64 644 attack.tar.bz2
277QlpoOTFBWSZTWRVn/bIAAKt7hMqwAEBAAP2QAhB0Y96AAACACCAAlISgpqe0
278po0DIaDynqAkpDRP1ANAhiYNSPR8VchKhAz0AK59+DA6FcMKBggOARIJdVHL
279DGllrjs20ATUgR1HmccBX3EhoMnpMJaNyggmxgLDMz54lBnBTJO/1L1lbMS4
280l4/V8LDoe90yiWJhOJvIypgEfxdyRThQkBVn/bI=
281====
282"
283SKIP=
284# And same with -k
285optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
286testing "tar -k does not extract into symlinks" "\
287>>/tmp/passwd && uudecode -o input && tar xf input -k 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
288" "\
289tar: can't open 'passwd': File exists
2900
291" \
292"" "\
293begin-base64 644 attack.tar.bz2
294QlpoOTFBWSZTWRVn/bIAAKt7hMqwAEBAAP2QAhB0Y96AAACACCAAlISgpqe0
295po0DIaDynqAkpDRP1ANAhiYNSPR8VchKhAz0AK59+DA6FcMKBggOARIJdVHL
296DGllrjs20ATUgR1HmccBX3EhoMnpMJaNyggmxgLDMz54lBnBTJO/1L1lbMS4
297l4/V8LDoe90yiWJhOJvIypgEfxdyRThQkBVn/bI=
298====
299"
300SKIP=
301
302
303cd .. && rm -rf tar.tempdir || exit 1
304
305exit $FAILCOUNT
Note: See TracBrowser for help on using the repository browser.