aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-11-19 17:17:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-11-19 17:17:48 +0100
commit0545e3b69ab57af1c21d199611c56b7f7593c8c5 (patch)
treee085c0df969e977e3a6f1b247759d40eacf57129
parentdd1d8ab506420014cf0a3a076b2e3a4fa5de16ee (diff)
downloadbusybox-w32-0545e3b69ab57af1c21d199611c56b7f7593c8c5.tar.gz
busybox-w32-0545e3b69ab57af1c21d199611c56b7f7593c8c5.tar.bz2
busybox-w32-0545e3b69ab57af1c21d199611c56b7f7593c8c5.zip
tar: prevent empty file to be treated as valid tarball
function old new delta tar_main 879 895 +16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/tar.c13
-rwxr-xr-xtestsuite/tar.tests25
2 files changed, 35 insertions, 3 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 3877ea4db..bd61abd57 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1196,8 +1196,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1196 /*tar_handle->offset = 0; - already is */ 1196 /*tar_handle->offset = 0; - already is */
1197 } 1197 }
1198 1198
1199 /* Zero processed headers (== empty file) is not a valid tarball.
1200 * We (ab)use bb_got_signal as exitcode here,
1201 * because check_errors_in_children() uses _it_ as error indicator.
1202 */
1203 bb_got_signal = EXIT_FAILURE;
1204
1199 while (get_header_tar(tar_handle) == EXIT_SUCCESS) 1205 while (get_header_tar(tar_handle) == EXIT_SUCCESS)
1200 continue; 1206 bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
1201 1207
1202 /* Check that every file that should have been extracted was */ 1208 /* Check that every file that should have been extracted was */
1203 while (tar_handle->accept) { 1209 while (tar_handle->accept) {
@@ -1213,8 +1219,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1213 close(tar_handle->src_fd); 1219 close(tar_handle->src_fd);
1214 1220
1215 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { 1221 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
1222 /* Set bb_got_signal to 1 if a child died with !0 exitcode */
1216 check_errors_in_children(0); 1223 check_errors_in_children(0);
1217 return bb_got_signal;
1218 } 1224 }
1219 return EXIT_SUCCESS; 1225
1226 return bb_got_signal;
1220} 1227}
diff --git a/testsuite/tar.tests b/testsuite/tar.tests
index c947d3382..93ba5f004 100755
--- a/testsuite/tar.tests
+++ b/testsuite/tar.tests
@@ -15,6 +15,15 @@ mkdir tar.tempdir && cd tar.tempdir || exit 1
15 15
16# testing "test name" "script" "expected result" "file input" "stdin" 16# testing "test name" "script" "expected result" "file input" "stdin"
17 17
18testing "Empty file is not a tarball" '\
19tar xvf - 2>&1; echo $?
20' "\
21tar: short read
221
23" \
24"" ""
25SKIP=
26
18optional FEATURE_SEAMLESS_GZ 27optional FEATURE_SEAMLESS_GZ
19testing "Empty file is not a tarball.tar.gz" '\ 28testing "Empty file is not a tarball.tar.gz" '\
20tar xvzf - 2>&1; echo $? 29tar xvzf - 2>&1; echo $?
@@ -26,6 +35,22 @@ tar: short read
26"" "" 35"" ""
27SKIP= 36SKIP=
28 37
38testing "Two zeroed blocks is a ('truncated') empty tarball" '\
39dd if=/dev/zero bs=512 count=2 2>/dev/null | strace -o /tmp/zzz -tt -s99 tar xvf - 2>&1; echo $?
40' "\
410
42" \
43"" ""
44SKIP=
45
46testing "Twenty zeroed blocks is an empty tarball" '\
47dd if=/dev/zero bs=512 count=20 2>/dev/null | tar xvf - 2>&1; echo $?
48' "\
490
50" \
51"" ""
52SKIP=
53
29optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES 54optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
30testing "tar hardlinks and repeated files" '\ 55testing "tar hardlinks and repeated files" '\
31rm -rf input_* test.tar 2>/dev/null 56rm -rf input_* test.tar 2>/dev/null