diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-22 00:21:07 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-22 00:21:07 +0000 |
commit | 714701c890b5f03253c5ecdb7367c4258ce78715 (patch) | |
tree | 7ddaf73cf2deda0f357b21802dab4d42798dd778 /archival | |
parent | 0a8a7741795880201bcf78231d1eab0e2538bb0b (diff) | |
download | busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.tar.gz busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.tar.bz2 busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.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)
Diffstat (limited to 'archival')
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 4 | ||||
-rw-r--r-- | archival/libunarchive/data_extract_to_buffer.c | 3 | ||||
-rw-r--r-- | archival/libunarchive/data_extract_to_stdout.c | 6 | ||||
-rw-r--r-- | archival/libunarchive/get_header_ar.c | 3 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/seek_by_read.c | 5 | ||||
-rw-r--r-- | archival/tar.c | 32 | ||||
-rw-r--r-- | archival/unzip.c | 23 |
8 files changed, 37 insertions, 41 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index 67f8f3534..25bf028d2 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c | |||
@@ -67,10 +67,10 @@ void data_extract_all(archive_handle_t *archive_handle) | |||
67 | /* Regular file */ | 67 | /* Regular file */ |
68 | dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL, | 68 | dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL, |
69 | file_header->mode); | 69 | file_header->mode); |
70 | bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); | 70 | bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size); |
71 | close(dst_fd); | 71 | close(dst_fd); |
72 | break; | 72 | break; |
73 | } | 73 | } |
74 | case S_IFDIR: | 74 | case S_IFDIR: |
75 | res = mkdir(file_header->name, file_header->mode); | 75 | res = mkdir(file_header->name, file_header->mode); |
76 | if ((errno != EISDIR) && (res == -1) | 76 | if ((errno != EISDIR) && (res == -1) |
diff --git a/archival/libunarchive/data_extract_to_buffer.c b/archival/libunarchive/data_extract_to_buffer.c index 95cb8f576..d8fcdf3d3 100644 --- a/archival/libunarchive/data_extract_to_buffer.c +++ b/archival/libunarchive/data_extract_to_buffer.c | |||
@@ -10,9 +10,8 @@ | |||
10 | 10 | ||
11 | void data_extract_to_buffer(archive_handle_t *archive_handle) | 11 | void data_extract_to_buffer(archive_handle_t *archive_handle) |
12 | { | 12 | { |
13 | const unsigned int size = archive_handle->file_header->size; | 13 | unsigned int size = archive_handle->file_header->size; |
14 | 14 | ||
15 | archive_handle->buffer = xzalloc(size + 1); | 15 | archive_handle->buffer = xzalloc(size + 1); |
16 | |||
17 | xread(archive_handle->src_fd, archive_handle->buffer, size); | 16 | xread(archive_handle->src_fd, archive_handle->buffer, size); |
18 | } | 17 | } |
diff --git a/archival/libunarchive/data_extract_to_stdout.c b/archival/libunarchive/data_extract_to_stdout.c index 788246ce7..2e266c046 100644 --- a/archival/libunarchive/data_extract_to_stdout.c +++ b/archival/libunarchive/data_extract_to_stdout.c | |||
@@ -4,9 +4,11 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "unarchive.h" | 6 | #include "unarchive.h" |
7 | #include <unistd.h> | 7 | //#include <unistd.h> |
8 | 8 | ||
9 | void data_extract_to_stdout(archive_handle_t *archive_handle) | 9 | void data_extract_to_stdout(archive_handle_t *archive_handle) |
10 | { | 10 | { |
11 | bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size); | 11 | bb_copyfd_exact_size(archive_handle->src_fd, |
12 | STDOUT_FILENO, | ||
13 | archive_handle->file_header->size); | ||
12 | } | 14 | } |
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c index 7f8c81ca0..6638c65aa 100644 --- a/archival/libunarchive/get_header_ar.c +++ b/archival/libunarchive/get_header_ar.c | |||
@@ -96,7 +96,8 @@ char get_header_ar(archive_handle_t *archive_handle) | |||
96 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { | 96 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { |
97 | archive_handle->action_header(typed); | 97 | archive_handle->action_header(typed); |
98 | if (archive_handle->sub_archive) { | 98 | if (archive_handle->sub_archive) { |
99 | while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS); | 99 | while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS) |
100 | /* repeat */; | ||
100 | } else { | 101 | } else { |
101 | archive_handle->action_data(archive_handle); | 102 | archive_handle->action_data(archive_handle); |
102 | } | 103 | } |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 66c3314a1..beb8687c7 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -251,7 +251,7 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
251 | } | 251 | } |
252 | 252 | ||
253 | /* Strip trailing '/' in directories */ | 253 | /* Strip trailing '/' in directories */ |
254 | /* Must be done after mode is set as '/' is used to check if its a directory */ | 254 | /* Must be done after mode is set as '/' is used to check if it's a directory */ |
255 | cp = last_char_is(file_header->name, '/'); | 255 | cp = last_char_is(file_header->name, '/'); |
256 | 256 | ||
257 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { | 257 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { |
diff --git a/archival/libunarchive/seek_by_read.c b/archival/libunarchive/seek_by_read.c index d56f94b21..e46af4842 100644 --- a/archival/libunarchive/seek_by_read.c +++ b/archival/libunarchive/seek_by_read.c | |||
@@ -13,7 +13,6 @@ | |||
13 | */ | 13 | */ |
14 | void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size) | 14 | void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size) |
15 | { | 15 | { |
16 | if (jump_size) { | 16 | if (jump_size) |
17 | bb_copyfd_size(archive_handle->src_fd, -1, jump_size); | 17 | bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size); |
18 | } | ||
19 | } | 18 | } |
diff --git a/archival/tar.c b/archival/tar.c index 7465e881b..ee9007c47 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -452,26 +452,28 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
452 | 452 | ||
453 | /* If it was a regular file, write out the body */ | 453 | /* If it was a regular file, write out the body */ |
454 | if (inputFileFd >= 0) { | 454 | if (inputFileFd >= 0) { |
455 | off_t readSize = 0; | 455 | size_t readSize; |
456 | 456 | /* Wwrite the file to the archive. */ | |
457 | /* write the file to the archive */ | 457 | /* We record size into header first, */ |
458 | readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); | 458 | /* and then write out file. If file shrinks in between, */ |
459 | /* readSize < 0 means that error was already reported */ | 459 | /* tar will be corrupted. So we don't allow for that. */ |
460 | if (readSize != statbuf->st_size && readSize >= 0) { | 460 | /* NB: GNU tar 1.16 warns and pads with zeroes */ |
461 | /* Deadly. We record size into header first, */ | 461 | /* or even seeks back and updates header */ |
462 | /* and then write out file. If file shrinks in between, */ | 462 | bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); |
463 | /* tar will be corrupted. So bail out. */ | 463 | ////off_t readSize; |
464 | /* NB: GNU tar 1.16 warns and pads with zeroes */ | 464 | ////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size); |
465 | /* or even seeks back and updates header */ | 465 | ////if (readSize != statbuf->st_size && readSize >= 0) { |
466 | bb_error_msg_and_die("short read from %s, aborting", fileName); | 466 | //// bb_error_msg_and_die("short read from %s, aborting", fileName); |
467 | } | 467 | ////} |
468 | |||
468 | /* Check that file did not grow in between? */ | 469 | /* Check that file did not grow in between? */ |
469 | /* if (safe_read(inputFileFd,1) == 1) warn but continue? */ | 470 | /* if (safe_read(inputFileFd, 1) == 1) warn but continue? */ |
471 | |||
470 | close(inputFileFd); | 472 | close(inputFileFd); |
471 | 473 | ||
472 | /* Pad the file up to the tar block size */ | 474 | /* Pad the file up to the tar block size */ |
473 | /* (a few tricks here in the name of code size) */ | 475 | /* (a few tricks here in the name of code size) */ |
474 | readSize = (-(int)readSize) & (TAR_BLOCK_SIZE-1); | 476 | readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1); |
475 | memset(bb_common_bufsiz1, 0, readSize); | 477 | memset(bb_common_bufsiz1, 0, readSize); |
476 | xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize); | 478 | xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize); |
477 | } | 479 | } |
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 */ |