diff options
-rw-r--r-- | archival/bbunzip.c | 5 | ||||
-rw-r--r-- | archival/libarchive/get_header_tar.c | 2 | ||||
-rw-r--r-- | archival/libarchive/open_transformer.c | 19 | ||||
-rw-r--r-- | archival/rpm.c | 2 | ||||
-rw-r--r-- | archival/rpm2cpio.c | 2 | ||||
-rw-r--r-- | archival/tar.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 6 | ||||
-rw-r--r-- | miscutils/fbsplash.c | 2 | ||||
-rw-r--r-- | miscutils/man.c | 2 |
9 files changed, 17 insertions, 25 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 | */ |
121 | int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected) | 121 | int 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 | ||
183 | int FAST_FUNC open_zipped(const char *fname) | 183 | int 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 { |
diff --git a/include/libbb.h b/include/libbb.h index 64167bba3..96f33340e 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -736,12 +736,12 @@ extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAS | |||
736 | 736 | ||
737 | #if SEAMLESS_COMPRESSION | 737 | #if SEAMLESS_COMPRESSION |
738 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ | 738 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ |
739 | extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC; | 739 | extern int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC; |
740 | /* Autodetects .gz etc */ | 740 | /* Autodetects .gz etc */ |
741 | extern int open_zipped(const char *fname) FAST_FUNC; | 741 | extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC; |
742 | #else | 742 | #else |
743 | # define setup_unzip_on_fd(...) (0) | 743 | # define setup_unzip_on_fd(...) (0) |
744 | # define open_zipped(fname) open((fname), O_RDONLY); | 744 | # define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY); |
745 | #endif | 745 | #endif |
746 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 746 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
747 | 747 | ||
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 12a77b70f..7b695b26f 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c | |||
@@ -353,7 +353,7 @@ static void fb_drawimage(void) | |||
353 | if (LONE_DASH(G.image_filename)) { | 353 | if (LONE_DASH(G.image_filename)) { |
354 | theme_file = stdin; | 354 | theme_file = stdin; |
355 | } else { | 355 | } else { |
356 | int fd = open_zipped(G.image_filename); | 356 | int fd = open_zipped(G.image_filename, /*fail_if_not_compressed:*/ 0); |
357 | if (fd < 0) | 357 | if (fd < 0) |
358 | bb_simple_perror_msg_and_die(G.image_filename); | 358 | bb_simple_perror_msg_and_die(G.image_filename); |
359 | theme_file = xfdopen_for_read(fd); | 359 | theme_file = xfdopen_for_read(fd); |
diff --git a/miscutils/man.c b/miscutils/man.c index 51baceb16..f046e24f3 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
@@ -102,7 +102,7 @@ static int run_pipe(const char *pager, char *man_filename, int man, int level) | |||
102 | 102 | ||
103 | ordinary_manpage: | 103 | ordinary_manpage: |
104 | close(STDIN_FILENO); | 104 | close(STDIN_FILENO); |
105 | open_zipped(man_filename); /* guaranteed to use fd 0 (STDIN_FILENO) */ | 105 | open_zipped(man_filename, /*fail_if_not_compressed:*/ 0); /* guaranteed to use fd 0 (STDIN_FILENO) */ |
106 | /* "2>&1" is added so that nroff errors are shown in pager too. | 106 | /* "2>&1" is added so that nroff errors are shown in pager too. |
107 | * Otherwise it may show just empty screen */ | 107 | * Otherwise it may show just empty screen */ |
108 | cmd = xasprintf( | 108 | cmd = xasprintf( |