aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-02-02 02:06:38 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-02-02 02:06:38 +0100
commit640ce3de07807133796bccd0bdfa146bbfc788c7 (patch)
tree0d17e53405b8cbf71aed4d8ba6c9dc27df14814a /archival
parentf1999b5a9d2788cdc120b1ee2ab1de18e95b38f2 (diff)
downloadbusybox-w32-640ce3de07807133796bccd0bdfa146bbfc788c7.tar.gz
busybox-w32-640ce3de07807133796bccd0bdfa146bbfc788c7.tar.bz2
busybox-w32-640ce3de07807133796bccd0bdfa146bbfc788c7.zip
zcat: complain if input is not compressed
function old new delta buffer_fill_and_print 178 191 +13 varvalue 735 743 +8 bbunpack 747 755 +8 open_zipped 85 89 +4 xmalloc_open_zipped_read_close 61 63 +2 get_addr_1 240 242 +2 fbsplash_main 1228 1230 +2 pstree_main 322 321 -1 builtin_type 121 119 -2 do_load 954 926 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/3 up/down: 39/-31) Total: 8 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival')
-rw-r--r--archival/bbunzip.c5
-rw-r--r--archival/libarchive/get_header_tar.c2
-rw-r--r--archival/libarchive/open_transformer.c19
-rw-r--r--archival/rpm.c2
-rw-r--r--archival/rpm2cpio.c2
-rw-r--r--archival/tar.c2
6 files changed, 12 insertions, 20 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index b3fb90f31..fce5ab9e1 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -72,7 +72,8 @@ int FAST_FUNC bbunpack(char **argv,
72 goto err; 72 goto err;
73 } else { 73 } else {
74 /* "clever zcat" with FILE */ 74 /* "clever zcat" with FILE */
75 int fd = open_zipped(filename); 75 /* fail_if_not_compressed because zcat refuses uncompressed input */
76 int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
76 if (fd < 0) 77 if (fd < 0)
77 goto err_name; 78 goto err_name;
78 xmove_fd(fd, STDIN_FILENO); 79 xmove_fd(fd, STDIN_FILENO);
@@ -80,7 +81,7 @@ int FAST_FUNC bbunpack(char **argv,
80 } else 81 } else
81 if (option_mask32 & SEAMLESS_MAGIC) { 82 if (option_mask32 & SEAMLESS_MAGIC) {
82 /* "clever zcat" on stdin */ 83 /* "clever zcat" on stdin */
83 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0)) 84 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
84 goto err; 85 goto err;
85 } 86 }
86 87
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 54d910431..ba43bb073 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -243,7 +243,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
243 * or not first block (false positive, it's not .gz/.bz2!) */ 243 * or not first block (false positive, it's not .gz/.bz2!) */
244 if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0) 244 if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
245 goto err; 245 goto err;
246 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0) 246 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
247 err: 247 err:
248 bb_error_msg_and_die("invalid tar magic"); 248 bb_error_msg_and_die("invalid tar magic");
249 archive_handle->offset = 0; 249 archive_handle->offset = 0;
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index 27854af21..198663041 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -118,7 +118,7 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
118/* Used by e.g. rpm which gives us a fd without filename, 118/* Used by e.g. rpm which gives us a fd without filename,
119 * thus we can't guess the format from filename's extension. 119 * thus we can't guess the format from filename's extension.
120 */ 120 */
121int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected) 121int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
122{ 122{
123 union { 123 union {
124 uint8_t b[4]; 124 uint8_t b[4];
@@ -159,7 +159,7 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
159 } 159 }
160 160
161 /* No known magic seen */ 161 /* No known magic seen */
162 if (fail_if_not_detected) 162 if (fail_if_not_compressed)
163 bb_error_msg_and_die("no gzip" 163 bb_error_msg_and_die("no gzip"
164 IF_FEATURE_SEAMLESS_BZ2("/bzip2") 164 IF_FEATURE_SEAMLESS_BZ2("/bzip2")
165 IF_FEATURE_SEAMLESS_XZ("/xz") 165 IF_FEATURE_SEAMLESS_XZ("/xz")
@@ -180,7 +180,7 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
180 return 0; 180 return 0;
181} 181}
182 182
183int FAST_FUNC open_zipped(const char *fname) 183int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
184{ 184{
185 int fd; 185 int fd;
186 186
@@ -200,16 +200,7 @@ int FAST_FUNC open_zipped(const char *fname)
200 || (ENABLE_FEATURE_SEAMLESS_BZ2) 200 || (ENABLE_FEATURE_SEAMLESS_BZ2)
201 || (ENABLE_FEATURE_SEAMLESS_XZ) 201 || (ENABLE_FEATURE_SEAMLESS_XZ)
202 ) { 202 ) {
203 /* 203 setup_unzip_on_fd(fd, fail_if_not_compressed);
204 * Do we want to fail_if_not_detected?
205 * In most cases, no: think "insmod non_compressed_module".
206 * A case which would like to fail is "zcat uncompressed_file":
207 * otherwise, it happily outputs uncompressed_file as-is,
208 * which is, strictly speaking, not what is expected.
209 * If this ever becomes a problem, we can add
210 * fail_if_not_detected bool argument to open_zipped().
211 */
212 setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 0);
213 } 204 }
214 205
215 return fd; 206 return fd;
@@ -222,7 +213,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
222 int fd; 213 int fd;
223 char *image; 214 char *image;
224 215
225 fd = open_zipped(fname); 216 fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
226 if (fd < 0) 217 if (fd < 0)
227 return NULL; 218 return NULL;
228 219
diff --git a/archival/rpm.c b/archival/rpm.c
index 885eddd64..105394481 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -122,7 +122,7 @@ static void extract_cpio(int fd, const char *source_rpm)
122 archive_handle->src_fd = fd; 122 archive_handle->src_fd = fd;
123 /*archive_handle->offset = 0; - init_handle() did it */ 123 /*archive_handle->offset = 0; - init_handle() did it */
124 124
125 setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1); 125 setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
126 while (get_header_cpio(archive_handle) == EXIT_SUCCESS) 126 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
127 continue; 127 continue;
128} 128}
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 61adde795..7057570f5 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
80 // signal(SIGCHLD, check_errors_in_children); 80 // signal(SIGCHLD, check_errors_in_children);
81 81
82 /* This works, but doesn't report uncompress errors (they happen in child) */ 82 /* This works, but doesn't report uncompress errors (they happen in child) */
83 setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1); 83 setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
84 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) 84 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
85 bb_error_msg_and_die("error unpacking"); 85 bb_error_msg_and_die("error unpacking");
86 86
diff --git a/archival/tar.c b/archival/tar.c
index bd61abd57..aa02d3512 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1137,7 +1137,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1137 && flags == O_RDONLY 1137 && flags == O_RDONLY
1138 && !(opt & OPT_ANY_COMPRESS) 1138 && !(opt & OPT_ANY_COMPRESS)
1139 ) { 1139 ) {
1140 tar_handle->src_fd = open_zipped(tar_filename); 1140 tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
1141 if (tar_handle->src_fd < 0) 1141 if (tar_handle->src_fd < 0)
1142 bb_perror_msg_and_die("can't open '%s'", tar_filename); 1142 bb_perror_msg_and_die("can't open '%s'", tar_filename);
1143 } else { 1143 } else {