diff options
author | Ron Yorston <rmy@pobox.com> | 2015-03-14 20:33:00 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-03-14 20:33:00 +0000 |
commit | a4f58436b78fe59e57620c6e0301f213ee25f273 (patch) | |
tree | 8355f724926e605280af2d6f2b1ccc6b1bd02dee /archival/libarchive | |
parent | ba0c36cfcf84efbac6f89e27238e04bb57e9cd45 (diff) | |
parent | 49acc1a7618a28d34381cbb7661d7c981fcb238f (diff) | |
download | busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.tar.gz busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.tar.bz2 busybox-w32-a4f58436b78fe59e57620c6e0301f213ee25f273.zip |
Merge branch 'busybox' into merge
Conflicts:
coreutils/od_bloaty.c
libbb/lineedit.c
Diffstat (limited to 'archival/libarchive')
-rw-r--r-- | archival/libarchive/Kbuild.src | 6 | ||||
-rw-r--r-- | archival/libarchive/filter_accept_list_reassign.c | 10 | ||||
-rw-r--r-- | archival/libarchive/get_header_cpio.c | 2 | ||||
-rw-r--r-- | archival/libarchive/get_header_tar.c | 36 | ||||
-rw-r--r-- | archival/libarchive/get_header_tar_xz.c | 21 | ||||
-rw-r--r-- | archival/libarchive/unpack_ar_archive.c | 2 | ||||
-rw-r--r-- | archival/libarchive/unsafe_prefix.c | 36 |
7 files changed, 76 insertions, 37 deletions
diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src index 968fdf8ab..b7faaf77f 100644 --- a/archival/libarchive/Kbuild.src +++ b/archival/libarchive/Kbuild.src | |||
@@ -30,11 +30,13 @@ COMMON_FILES:= \ | |||
30 | DPKG_FILES:= \ | 30 | DPKG_FILES:= \ |
31 | unpack_ar_archive.o \ | 31 | unpack_ar_archive.o \ |
32 | filter_accept_list_reassign.o \ | 32 | filter_accept_list_reassign.o \ |
33 | unsafe_prefix.o \ | ||
33 | get_header_ar.o \ | 34 | get_header_ar.o \ |
34 | get_header_tar.o \ | 35 | get_header_tar.o \ |
35 | get_header_tar_gz.o \ | 36 | get_header_tar_gz.o \ |
36 | get_header_tar_bz2.o \ | 37 | get_header_tar_bz2.o \ |
37 | get_header_tar_lzma.o \ | 38 | get_header_tar_lzma.o \ |
39 | get_header_tar_xz.o \ | ||
38 | 40 | ||
39 | INSERT | 41 | INSERT |
40 | 42 | ||
@@ -43,7 +45,7 @@ lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) | |||
43 | 45 | ||
44 | lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o | 46 | lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o |
45 | lib-$(CONFIG_CPIO) += get_header_cpio.o | 47 | lib-$(CONFIG_CPIO) += get_header_cpio.o |
46 | lib-$(CONFIG_TAR) += get_header_tar.o | 48 | lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o |
47 | lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o | 49 | lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o |
48 | lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o | 50 | lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o |
49 | lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o | 51 | lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o |
@@ -52,7 +54,7 @@ lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma. | |||
52 | lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o | 54 | lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o |
53 | lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o | 55 | lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o |
54 | lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o | 56 | lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o |
55 | lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o | 57 | lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o |
56 | lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o | 58 | lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o |
57 | lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o | 59 | lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o |
58 | 60 | ||
diff --git a/archival/libarchive/filter_accept_list_reassign.c b/archival/libarchive/filter_accept_list_reassign.c index 3d19abe44..b9acfbc05 100644 --- a/archival/libarchive/filter_accept_list_reassign.c +++ b/archival/libarchive/filter_accept_list_reassign.c | |||
@@ -28,6 +28,10 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle) | |||
28 | name_ptr++; | 28 | name_ptr++; |
29 | 29 | ||
30 | /* Modify the subarchive handler based on the extension */ | 30 | /* Modify the subarchive handler based on the extension */ |
31 | if (strcmp(name_ptr, "tar") == 0) { | ||
32 | archive_handle->dpkg__action_data_subarchive = get_header_tar; | ||
33 | return EXIT_SUCCESS; | ||
34 | } | ||
31 | if (ENABLE_FEATURE_SEAMLESS_GZ | 35 | if (ENABLE_FEATURE_SEAMLESS_GZ |
32 | && strcmp(name_ptr, "gz") == 0 | 36 | && strcmp(name_ptr, "gz") == 0 |
33 | ) { | 37 | ) { |
@@ -46,6 +50,12 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle) | |||
46 | archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma; | 50 | archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma; |
47 | return EXIT_SUCCESS; | 51 | return EXIT_SUCCESS; |
48 | } | 52 | } |
53 | if (ENABLE_FEATURE_SEAMLESS_XZ | ||
54 | && strcmp(name_ptr, "xz") == 0 | ||
55 | ) { | ||
56 | archive_handle->dpkg__action_data_subarchive = get_header_tar_xz; | ||
57 | return EXIT_SUCCESS; | ||
58 | } | ||
49 | } | 59 | } |
50 | return EXIT_FAILURE; | 60 | return EXIT_FAILURE; |
51 | } | 61 | } |
diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c index 1a0058b63..7861d1f6f 100644 --- a/archival/libarchive/get_header_cpio.c +++ b/archival/libarchive/get_header_cpio.c | |||
@@ -37,7 +37,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
37 | } | 37 | } |
38 | archive_handle->offset += 110; | 38 | archive_handle->offset += 110; |
39 | 39 | ||
40 | if (strncmp(&cpio_header[0], "07070", 5) != 0 | 40 | if (!is_prefixed_with(&cpio_header[0], "07070") |
41 | || (cpio_header[5] != '1' && cpio_header[5] != '2') | 41 | || (cpio_header[5] != '1' && cpio_header[5] != '2') |
42 | ) { | 42 | ) { |
43 | bb_error_msg_and_die("unsupported cpio format, use newc or crc"); | 43 | bb_error_msg_and_die("unsupported cpio format, use newc or crc"); |
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index ba43bb073..2dbcdb50c 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c | |||
@@ -17,36 +17,6 @@ | |||
17 | typedef uint32_t aliased_uint32_t FIX_ALIASING; | 17 | typedef uint32_t aliased_uint32_t FIX_ALIASING; |
18 | typedef off_t aliased_off_t FIX_ALIASING; | 18 | typedef off_t aliased_off_t FIX_ALIASING; |
19 | 19 | ||
20 | |||
21 | const char* FAST_FUNC strip_unsafe_prefix(const char *str) | ||
22 | { | ||
23 | const char *cp = str; | ||
24 | while (1) { | ||
25 | char *cp2; | ||
26 | if (*cp == '/') { | ||
27 | cp++; | ||
28 | continue; | ||
29 | } | ||
30 | if (strncmp(cp, "/../"+1, 3) == 0) { | ||
31 | cp += 3; | ||
32 | continue; | ||
33 | } | ||
34 | cp2 = strstr(cp, "/../"); | ||
35 | if (!cp2) | ||
36 | break; | ||
37 | cp = cp2 + 4; | ||
38 | } | ||
39 | if (cp != str) { | ||
40 | static smallint warned = 0; | ||
41 | if (!warned) { | ||
42 | warned = 1; | ||
43 | bb_error_msg("removing leading '%.*s' from member names", | ||
44 | (int)(cp - str), str); | ||
45 | } | ||
46 | } | ||
47 | return cp; | ||
48 | } | ||
49 | |||
50 | /* NB: _DESTROYS_ str[len] character! */ | 20 | /* NB: _DESTROYS_ str[len] character! */ |
51 | static unsigned long long getOctal(char *str, int len) | 21 | static unsigned long long getOctal(char *str, int len) |
52 | { | 22 | { |
@@ -135,7 +105,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g | |||
135 | value = end + 1; | 105 | value = end + 1; |
136 | 106 | ||
137 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS | 107 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
138 | if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) { | 108 | if (!global && is_prefixed_with(value, "path=")) { |
139 | value += sizeof("path=") - 1; | 109 | value += sizeof("path=") - 1; |
140 | free(archive_handle->tar__longname); | 110 | free(archive_handle->tar__longname); |
141 | archive_handle->tar__longname = xstrdup(value); | 111 | archive_handle->tar__longname = xstrdup(value); |
@@ -148,7 +118,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g | |||
148 | * This is what Red Hat's patched version of tar uses. | 118 | * This is what Red Hat's patched version of tar uses. |
149 | */ | 119 | */ |
150 | # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" | 120 | # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" |
151 | if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) { | 121 | if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) { |
152 | value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; | 122 | value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; |
153 | free(archive_handle->tar__sctx[global]); | 123 | free(archive_handle->tar__sctx[global]); |
154 | archive_handle->tar__sctx[global] = xstrdup(value); | 124 | archive_handle->tar__sctx[global] = xstrdup(value); |
@@ -232,7 +202,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
232 | 202 | ||
233 | /* Check header has valid magic, "ustar" is for the proper tar, | 203 | /* Check header has valid magic, "ustar" is for the proper tar, |
234 | * five NULs are for the old tar format */ | 204 | * five NULs are for the old tar format */ |
235 | if (strncmp(tar.magic, "ustar", 5) != 0 | 205 | if (!is_prefixed_with(tar.magic, "ustar") |
236 | && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY | 206 | && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY |
237 | || memcmp(tar.magic, "\0\0\0\0", 5) != 0) | 207 | || memcmp(tar.magic, "\0\0\0\0", 5) != 0) |
238 | ) { | 208 | ) { |
diff --git a/archival/libarchive/get_header_tar_xz.c b/archival/libarchive/get_header_tar_xz.c new file mode 100644 index 000000000..7bf3b3b56 --- /dev/null +++ b/archival/libarchive/get_header_tar_xz.c | |||
@@ -0,0 +1,21 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
4 | */ | ||
5 | |||
6 | #include "libbb.h" | ||
7 | #include "bb_archive.h" | ||
8 | |||
9 | char FAST_FUNC get_header_tar_xz(archive_handle_t *archive_handle) | ||
10 | { | ||
11 | /* Can't lseek over pipes */ | ||
12 | archive_handle->seek = seek_by_read; | ||
13 | |||
14 | fork_transformer_with_sig(archive_handle->src_fd, unpack_xz_stream, "unxz"); | ||
15 | archive_handle->offset = 0; | ||
16 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) | ||
17 | continue; | ||
18 | |||
19 | /* Can only do one file at a time */ | ||
20 | return EXIT_FAILURE; | ||
21 | } | ||
diff --git a/archival/libarchive/unpack_ar_archive.c b/archival/libarchive/unpack_ar_archive.c index 214d17e23..0bc030349 100644 --- a/archival/libarchive/unpack_ar_archive.c +++ b/archival/libarchive/unpack_ar_archive.c | |||
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive) | |||
12 | char magic[7]; | 12 | char magic[7]; |
13 | 13 | ||
14 | xread(ar_archive->src_fd, magic, AR_MAGIC_LEN); | 14 | xread(ar_archive->src_fd, magic, AR_MAGIC_LEN); |
15 | if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) { | 15 | if (!is_prefixed_with(magic, AR_MAGIC)) { |
16 | bb_error_msg_and_die("invalid ar magic"); | 16 | bb_error_msg_and_die("invalid ar magic"); |
17 | } | 17 | } |
18 | ar_archive->offset += AR_MAGIC_LEN; | 18 | ar_archive->offset += AR_MAGIC_LEN; |
diff --git a/archival/libarchive/unsafe_prefix.c b/archival/libarchive/unsafe_prefix.c new file mode 100644 index 000000000..9994f4d94 --- /dev/null +++ b/archival/libarchive/unsafe_prefix.c | |||
@@ -0,0 +1,36 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
4 | */ | ||
5 | |||
6 | #include "libbb.h" | ||
7 | #include "bb_archive.h" | ||
8 | |||
9 | const char* FAST_FUNC strip_unsafe_prefix(const char *str) | ||
10 | { | ||
11 | const char *cp = str; | ||
12 | while (1) { | ||
13 | char *cp2; | ||
14 | if (*cp == '/') { | ||
15 | cp++; | ||
16 | continue; | ||
17 | } | ||
18 | if (is_prefixed_with(cp, "/../"+1)) { | ||
19 | cp += 3; | ||
20 | continue; | ||
21 | } | ||
22 | cp2 = strstr(cp, "/../"); | ||
23 | if (!cp2) | ||
24 | break; | ||
25 | cp = cp2 + 4; | ||
26 | } | ||
27 | if (cp != str) { | ||
28 | static smallint warned = 0; | ||
29 | if (!warned) { | ||
30 | warned = 1; | ||
31 | bb_error_msg("removing leading '%.*s' from member names", | ||
32 | (int)(cp - str), str); | ||
33 | } | ||
34 | } | ||
35 | return cp; | ||
36 | } | ||