diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-22 00:21:07 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-22 00:21:07 +0000 |
commit | 2ae5f6f7b023c362db59c8ecf16c416bf1f77a75 (patch) | |
tree | 7ddaf73cf2deda0f357b21802dab4d42798dd778 /archival/unzip.c | |
parent | d8c6309724259aa293ac194650a154c4dbc154db (diff) | |
download | busybox-w32-2ae5f6f7b023c362db59c8ecf16c416bf1f77a75.tar.gz busybox-w32-2ae5f6f7b023c362db59c8ecf16c416bf1f77a75.tar.bz2 busybox-w32-2ae5f6f7b023c362db59c8ecf16c416bf1f77a75.zip |
tar et al: die if bb_copyfd_size copies less than asked for.
(we have bb_copyfd_exact_size now for that kind of usage)
git-svn-id: svn://busybox.net/trunk/busybox@17038 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'archival/unzip.c')
-rw-r--r-- | archival/unzip.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index f553eefa2..1c03a4c47 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -54,9 +54,9 @@ typedef union { | |||
54 | static void unzip_skip(int fd, off_t skip) | 54 | static void unzip_skip(int fd, off_t skip) |
55 | { | 55 | { |
56 | if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { | 56 | if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { |
57 | if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) { | 57 | if (errno != ESPIPE) |
58 | bb_error_msg_and_die("seek failure"); | 58 | bb_error_msg_and_die("seek failure"); |
59 | } | 59 | bb_copyfd_exact_size(fd, -1, skip); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
@@ -75,10 +75,8 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | |||
75 | if (zip_header->formatted.method == 0) { | 75 | if (zip_header->formatted.method == 0) { |
76 | /* Method 0 - stored (not compressed) */ | 76 | /* Method 0 - stored (not compressed) */ |
77 | off_t size = zip_header->formatted.ucmpsize; | 77 | off_t size = zip_header->formatted.ucmpsize; |
78 | if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) { | 78 | if (size) |
79 | bb_error_msg_and_die("cannot complete extraction"); | 79 | bb_copyfd_exact_size(src_fd, dst_fd, size); |
80 | } | ||
81 | |||
82 | } else { | 80 | } else { |
83 | /* Method 8 - inflate */ | 81 | /* Method 8 - inflate */ |
84 | inflate_init(zip_header->formatted.cmpsize); | 82 | inflate_init(zip_header->formatted.cmpsize); |
@@ -249,8 +247,8 @@ int unzip_main(int argc, char **argv) | |||
249 | unzip_skip(src_fd, zip_header.formatted.extra_len); | 247 | unzip_skip(src_fd, zip_header.formatted.extra_len); |
250 | 248 | ||
251 | if ((verbosity == v_list) && !list_header_done){ | 249 | if ((verbosity == v_list) && !list_header_done){ |
252 | printf(" Length Date Time Name\n" | 250 | puts(" Length Date Time Name\n" |
253 | " -------- ---- ---- ----\n"); | 251 | " -------- ---- ---- ----"); |
254 | list_header_done = 1; | 252 | list_header_done = 1; |
255 | } | 253 | } |
256 | 254 | ||
@@ -274,10 +272,8 @@ int unzip_main(int argc, char **argv) | |||
274 | dst_fn); | 272 | dst_fn); |
275 | total_entries++; | 273 | total_entries++; |
276 | i = 'n'; | 274 | i = 'n'; |
277 | |||
278 | } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ | 275 | } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ |
279 | i = -1; | 276 | i = -1; |
280 | |||
281 | } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ | 277 | } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ |
282 | if (stat(dst_fn, &stat_buf) == -1) { | 278 | if (stat(dst_fn, &stat_buf) == -1) { |
283 | if (errno != ENOENT) { | 279 | if (errno != ENOENT) { |
@@ -298,17 +294,15 @@ int unzip_main(int argc, char **argv) | |||
298 | i = 'n'; | 294 | i = 'n'; |
299 | 295 | ||
300 | } else { /* Extract file */ | 296 | } else { /* Extract file */ |
301 | _check_file: | 297 | _check_file: |
302 | if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ | 298 | if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ |
303 | if (errno != ENOENT) { | 299 | if (errno != ENOENT) { |
304 | bb_perror_msg_and_die("cannot stat '%s'",dst_fn); | 300 | bb_perror_msg_and_die("cannot stat '%s'",dst_fn); |
305 | } | 301 | } |
306 | i = 'y'; | 302 | i = 'y'; |
307 | |||
308 | } else { /* File already exists */ | 303 | } else { /* File already exists */ |
309 | if (overwrite == o_never) { | 304 | if (overwrite == o_never) { |
310 | i = 'n'; | 305 | i = 'n'; |
311 | |||
312 | } else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */ | 306 | } else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */ |
313 | if (overwrite == o_always) { | 307 | if (overwrite == o_always) { |
314 | i = 'y'; | 308 | i = 'y'; |
@@ -319,7 +313,6 @@ int unzip_main(int argc, char **argv) | |||
319 | } | 313 | } |
320 | i = key_buf[0]; | 314 | i = key_buf[0]; |
321 | } | 315 | } |
322 | |||
323 | } else { /* File is not regular file */ | 316 | } else { /* File is not regular file */ |
324 | bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn); | 317 | bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn); |
325 | } | 318 | } |
@@ -338,7 +331,7 @@ int unzip_main(int argc, char **argv) | |||
338 | printf(" inflating: %s\n", dst_fn); | 331 | printf(" inflating: %s\n", dst_fn); |
339 | } | 332 | } |
340 | if (unzip_extract(&zip_header, src_fd, dst_fd)) { | 333 | if (unzip_extract(&zip_header, src_fd, dst_fd)) { |
341 | failed = 1; | 334 | failed = 1; |
342 | } | 335 | } |
343 | if (dst_fd != STDOUT_FILENO) { | 336 | if (dst_fd != STDOUT_FILENO) { |
344 | /* closing STDOUT is potentially bad for future business */ | 337 | /* closing STDOUT is potentially bad for future business */ |