aboutsummaryrefslogtreecommitdiff
path: root/archival/libarchive
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-03-14 20:33:00 +0000
committerRon Yorston <rmy@pobox.com>2015-03-14 20:33:00 +0000
commita4f58436b78fe59e57620c6e0301f213ee25f273 (patch)
tree8355f724926e605280af2d6f2b1ccc6b1bd02dee /archival/libarchive
parentba0c36cfcf84efbac6f89e27238e04bb57e9cd45 (diff)
parent49acc1a7618a28d34381cbb7661d7c981fcb238f (diff)
downloadbusybox-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.src6
-rw-r--r--archival/libarchive/filter_accept_list_reassign.c10
-rw-r--r--archival/libarchive/get_header_cpio.c2
-rw-r--r--archival/libarchive/get_header_tar.c36
-rw-r--r--archival/libarchive/get_header_tar_xz.c21
-rw-r--r--archival/libarchive/unpack_ar_archive.c2
-rw-r--r--archival/libarchive/unsafe_prefix.c36
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:= \
30DPKG_FILES:= \ 30DPKG_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
39INSERT 41INSERT
40 42
@@ -43,7 +45,7 @@ lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
43 45
44lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o 46lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
45lib-$(CONFIG_CPIO) += get_header_cpio.o 47lib-$(CONFIG_CPIO) += get_header_cpio.o
46lib-$(CONFIG_TAR) += get_header_tar.o 48lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o
47lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o 49lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
48lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o 50lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
49lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o 51lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
@@ -52,7 +54,7 @@ lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.
52lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o 54lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
53lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o 55lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
54lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o 56lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
55lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o 57lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o
56lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o 58lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
57lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o 59lib-$(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 @@
17typedef uint32_t aliased_uint32_t FIX_ALIASING; 17typedef uint32_t aliased_uint32_t FIX_ALIASING;
18typedef off_t aliased_off_t FIX_ALIASING; 18typedef off_t aliased_off_t FIX_ALIASING;
19 19
20
21const 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! */
51static unsigned long long getOctal(char *str, int len) 21static 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
9char 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
9const 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}