diff options
author | Eugene Rudoy <gene.devel@gmail.com> | 2017-11-07 08:03:36 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-11-09 12:45:50 +0100 |
commit | c6f213ade49a8591a2f6c815a73aed3babe0f566 (patch) | |
tree | 123041c9ae18499ad8a000faf652c5ab77748b9b | |
parent | 0a6772214002da55e982b06947320b8911a1975b (diff) | |
download | busybox-w32-c6f213ade49a8591a2f6c815a73aed3babe0f566.tar.gz busybox-w32-c6f213ade49a8591a2f6c815a73aed3babe0f566.tar.bz2 busybox-w32-c6f213ade49a8591a2f6c815a73aed3babe0f566.zip |
unzip: fix content listing and filtering when -j is used
Original Info-ZIP's unzip uses unstripped filenames
while doing content listing and filtering, i.e.
- in content listing mode -j is ignored completely
- filtering is applied to non-stripped names, -j
takes effect first while extracting the files
997ad2c64abbe931dffa3598b015c5de04e515cf strips path
components a little bit too early resulting in behavior
deviations.
Fix it by doing stripping after listing/filtering.
p.s. Info-ZIP's unzip behavior is the same as
that of tar in --strip-components=NUM mode
Signed-off-by: Eugene Rudoy <gene.devel@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/unzip.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 604166063..1ef4406d6 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -805,13 +805,6 @@ int unzip_main(int argc, char **argv) | |||
805 | /* Guard against "/abspath", "/../" and similar attacks */ | 805 | /* Guard against "/abspath", "/../" and similar attacks */ |
806 | overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn)); | 806 | overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn)); |
807 | 807 | ||
808 | if (opts & OPT_j) /* Strip paths? */ | ||
809 | overlapping_strcpy(dst_fn, bb_basename(dst_fn)); | ||
810 | |||
811 | /* Did this strip everything ("DIR/" case)? Then skip */ | ||
812 | if (!dst_fn[0]) | ||
813 | goto skip_cmpsize; | ||
814 | |||
815 | /* Filter zip entries */ | 808 | /* Filter zip entries */ |
816 | if (find_list_entry(zreject, dst_fn) | 809 | if (find_list_entry(zreject, dst_fn) |
817 | || (zaccept && !find_list_entry(zaccept, dst_fn)) | 810 | || (zaccept && !find_list_entry(zaccept, dst_fn)) |
@@ -876,6 +869,14 @@ int unzip_main(int argc, char **argv) | |||
876 | /* Extracting to STDOUT */ | 869 | /* Extracting to STDOUT */ |
877 | goto do_extract; | 870 | goto do_extract; |
878 | } | 871 | } |
872 | |||
873 | /* Strip paths (after -l: unzip -lj a.zip lists full names) */ | ||
874 | if (opts & OPT_j) | ||
875 | overlapping_strcpy(dst_fn, bb_basename(dst_fn)); | ||
876 | /* Did this strip everything ("DIR/" case)? Then skip */ | ||
877 | if (!dst_fn[0]) | ||
878 | goto skip_cmpsize; | ||
879 | |||
879 | if (last_char_is(dst_fn, '/')) { | 880 | if (last_char_is(dst_fn, '/')) { |
880 | int mode; | 881 | int mode; |
881 | 882 | ||