diff options
author | Paul Fox <pgf@brightstareng.com> | 2006-03-27 23:09:14 +0000 |
---|---|---|
committer | Paul Fox <pgf@brightstareng.com> | 2006-03-27 23:09:14 +0000 |
commit | 986ab525b808258a5a79ed2cded531cfae76f81d (patch) | |
tree | c36e6c521fb027869311b7cb5905fb9e7143c54f | |
parent | b3ede5abe2de41760a806ad7b5a8e40018abc2f4 (diff) | |
download | busybox-w32-986ab525b808258a5a79ed2cded531cfae76f81d.tar.gz busybox-w32-986ab525b808258a5a79ed2cded531cfae76f81d.tar.bz2 busybox-w32-986ab525b808258a5a79ed2cded531cfae76f81d.zip |
ensure that corrupted file extraction causes both a message and
a failure exit code. delay the error exit until all (good) files
have been extracted.
filesystem errors (nodes of wrong type, permission problems, etc)
still cause immediate failure.
-rw-r--r-- | archival/unzip.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 9cf987664..bb7197d3e 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -100,7 +100,7 @@ static void unzip_create_leading_dirs(char *fn) | |||
100 | free(name); | 100 | free(name); |
101 | } | 101 | } |
102 | 102 | ||
103 | static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | 103 | static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) |
104 | { | 104 | { |
105 | if (zip_header->formated.method == 0) { | 105 | if (zip_header->formated.method == 0) { |
106 | /* Method 0 - stored (not compressed) */ | 106 | /* Method 0 - stored (not compressed) */ |
@@ -117,12 +117,15 @@ static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | |||
117 | /* Validate decompression - crc */ | 117 | /* Validate decompression - crc */ |
118 | if (zip_header->formated.crc32 != (gunzip_crc ^ 0xffffffffL)) { | 118 | if (zip_header->formated.crc32 != (gunzip_crc ^ 0xffffffffL)) { |
119 | bb_error_msg("Invalid compressed data--crc error"); | 119 | bb_error_msg("Invalid compressed data--crc error"); |
120 | return 1; | ||
120 | } | 121 | } |
121 | /* Validate decompression - size */ | 122 | /* Validate decompression - size */ |
122 | if (zip_header->formated.ucmpsize != gunzip_bytes_out) { | 123 | if (zip_header->formated.ucmpsize != gunzip_bytes_out) { |
123 | bb_error_msg("Invalid compressed data--length error"); | 124 | bb_error_msg("Invalid compressed data--length error"); |
125 | return 1; | ||
124 | } | 126 | } |
125 | } | 127 | } |
128 | return 0; | ||
126 | } | 129 | } |
127 | 130 | ||
128 | int unzip_main(int argc, char **argv) | 131 | int unzip_main(int argc, char **argv) |
@@ -137,7 +140,7 @@ int unzip_main(int argc, char **argv) | |||
137 | llist_t *zaccept = NULL; | 140 | llist_t *zaccept = NULL; |
138 | llist_t *zreject = NULL; | 141 | llist_t *zreject = NULL; |
139 | char *base_dir = NULL; | 142 | char *base_dir = NULL; |
140 | int i, opt, opt_range = 0, list_header_done = 0; | 143 | int failed, i, opt, opt_range = 0, list_header_done = 0; |
141 | char key_buf[512]; | 144 | char key_buf[512]; |
142 | struct stat stat_buf; | 145 | struct stat stat_buf; |
143 | 146 | ||
@@ -240,6 +243,8 @@ int unzip_main(int argc, char **argv) | |||
240 | if (verbosity != v_silent) | 243 | if (verbosity != v_silent) |
241 | printf("Archive: %s\n", src_fn); | 244 | printf("Archive: %s\n", src_fn); |
242 | 245 | ||
246 | failed = 0; | ||
247 | |||
243 | while (1) { | 248 | while (1) { |
244 | unsigned int magic; | 249 | unsigned int magic; |
245 | 250 | ||
@@ -367,7 +372,9 @@ int unzip_main(int argc, char **argv) | |||
367 | if (verbosity == v_normal) { | 372 | if (verbosity == v_normal) { |
368 | printf(" inflating: %s\n", dst_fn); | 373 | printf(" inflating: %s\n", dst_fn); |
369 | } | 374 | } |
370 | unzip_extract(&zip_header, src_fd, dst_fd); | 375 | if (unzip_extract(&zip_header, src_fd, dst_fd)) { |
376 | failed = 1; | ||
377 | } | ||
371 | if (dst_fd != STDOUT_FILENO) { | 378 | if (dst_fd != STDOUT_FILENO) { |
372 | /* closing STDOUT is potentially bad for future business */ | 379 | /* closing STDOUT is potentially bad for future business */ |
373 | close(dst_fd); | 380 | close(dst_fd); |
@@ -409,7 +416,7 @@ int unzip_main(int argc, char **argv) | |||
409 | "%9d %d files\n", total_size, total_entries); | 416 | "%9d %d files\n", total_size, total_entries); |
410 | } | 417 | } |
411 | 418 | ||
412 | return(EXIT_SUCCESS); | 419 | return failed; |
413 | } | 420 | } |
414 | 421 | ||
415 | /* END CODE */ | 422 | /* END CODE */ |