aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-20 20:21:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-20 20:21:50 +0200
commitad37abf4231275d0991d42f9003666f1efd4114b (patch)
tree895930c1e464d4ddf168a2b0e7676ed3805aa2a4
parent997ad2c64abbe931dffa3598b015c5de04e515cf (diff)
downloadbusybox-w32-ad37abf4231275d0991d42f9003666f1efd4114b.tar.gz
busybox-w32-ad37abf4231275d0991d42f9003666f1efd4114b.tar.bz2
busybox-w32-ad37abf4231275d0991d42f9003666f1efd4114b.zip
unzip: sanitize filename length: malloc(1234mb) is not funny
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/unzip.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/archival/unzip.c b/archival/unzip.c
index d5bca08d4..b618c3617 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -318,6 +318,12 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
318}; 318};
319#endif 319#endif
320 320
321static void die_if_bad_fnamesize(unsigned sz)
322{
323 if (sz > 0xfff) /* more than 4k?! no funny business please */
324 bb_error_msg_and_die("bad archive");
325}
326
321static void unzip_skip(off_t skip) 327static void unzip_skip(off_t skip)
322{ 328{
323 if (skip != 0) 329 if (skip != 0)
@@ -340,8 +346,7 @@ static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
340{ 346{
341 char *target; 347 char *target;
342 348
343 if (zip->fmt.ucmpsize > 0xfff) /* no funny business please */ 349 die_if_bad_fnamesize(zip->fmt.ucmpsize);
344 bb_error_msg_and_die("bad archive");
345 350
346 if (zip->fmt.method == 0) { 351 if (zip->fmt.method == 0) {
347 /* Method 0 - stored (not compressed) */ 352 /* Method 0 - stored (not compressed) */
@@ -784,6 +789,7 @@ int unzip_main(int argc, char **argv)
784 789
785 /* Read filename */ 790 /* Read filename */
786 free(dst_fn); 791 free(dst_fn);
792 die_if_bad_fnamesize(zip.fmt.filename_len);
787 dst_fn = xzalloc(zip.fmt.filename_len + 1); 793 dst_fn = xzalloc(zip.fmt.filename_len + 1);
788 xread(zip_fd, dst_fn, zip.fmt.filename_len); 794 xread(zip_fd, dst_fn, zip.fmt.filename_len);
789 /* Skip extra header bytes */ 795 /* Skip extra header bytes */