diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-02-22 10:50:14 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-02-22 10:50:14 +0100 |
commit | 75197998c22b0760a1a6d5e94f750b12855ef82f (patch) | |
tree | 6c6c22ecd330a2794ce411d91ec4e5967ddf9a1e | |
parent | 669c40ed8ebf480c95ce36135104e474e361a7e6 (diff) | |
download | busybox-w32-75197998c22b0760a1a6d5e94f750b12855ef82f.tar.gz busybox-w32-75197998c22b0760a1a6d5e94f750b12855ef82f.tar.bz2 busybox-w32-75197998c22b0760a1a6d5e94f750b12855ef82f.zip |
unzip: clear SUID/GID bits, implement -K to not clear them
function old new delta
unzip_main 2656 2715 +59
packed_usage 34517 34552 +35
.rodata 105250 105251 +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 95/0) Total: 95 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/unzip.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index b27dd2187..691a2d81b 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -56,7 +56,7 @@ | |||
56 | //kbuild:lib-$(CONFIG_UNZIP) += unzip.o | 56 | //kbuild:lib-$(CONFIG_UNZIP) += unzip.o |
57 | 57 | ||
58 | //usage:#define unzip_trivial_usage | 58 | //usage:#define unzip_trivial_usage |
59 | //usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]" | 59 | //usage: "[-lnojpqK] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]" |
60 | //usage:#define unzip_full_usage "\n\n" | 60 | //usage:#define unzip_full_usage "\n\n" |
61 | //usage: "Extract FILEs from ZIP archive\n" | 61 | //usage: "Extract FILEs from ZIP archive\n" |
62 | //usage: "\n -l List contents (with -q for short form)" | 62 | //usage: "\n -l List contents (with -q for short form)" |
@@ -66,6 +66,7 @@ | |||
66 | //usage: "\n -p Write to stdout" | 66 | //usage: "\n -p Write to stdout" |
67 | //usage: "\n -t Test" | 67 | //usage: "\n -t Test" |
68 | //usage: "\n -q Quiet" | 68 | //usage: "\n -q Quiet" |
69 | //usage: "\n -K Do not clear SUID bit" | ||
69 | //usage: "\n -x FILE Exclude FILEs" | 70 | //usage: "\n -x FILE Exclude FILEs" |
70 | //usage: "\n -d DIR Extract into DIR" | 71 | //usage: "\n -d DIR Extract into DIR" |
71 | 72 | ||
@@ -494,6 +495,7 @@ int unzip_main(int argc, char **argv) | |||
494 | OPT_l = (1 << 0), | 495 | OPT_l = (1 << 0), |
495 | OPT_x = (1 << 1), | 496 | OPT_x = (1 << 1), |
496 | OPT_j = (1 << 2), | 497 | OPT_j = (1 << 2), |
498 | OPT_K = (1 << 3), | ||
497 | }; | 499 | }; |
498 | unsigned opts; | 500 | unsigned opts; |
499 | smallint quiet = 0; | 501 | smallint quiet = 0; |
@@ -559,7 +561,7 @@ int unzip_main(int argc, char **argv) | |||
559 | 561 | ||
560 | opts = 0; | 562 | opts = 0; |
561 | /* '-' makes getopt return 1 for non-options */ | 563 | /* '-' makes getopt return 1 for non-options */ |
562 | while ((i = getopt(argc, argv, "-d:lnotpqxjv")) != -1) { | 564 | while ((i = getopt(argc, argv, "-d:lnotpqxjvK")) != -1) { |
563 | switch (i) { | 565 | switch (i) { |
564 | case 'd': /* Extract to base directory */ | 566 | case 'd': /* Extract to base directory */ |
565 | base_dir = optarg; | 567 | base_dir = optarg; |
@@ -602,6 +604,10 @@ int unzip_main(int argc, char **argv) | |||
602 | opts |= OPT_j; | 604 | opts |= OPT_j; |
603 | break; | 605 | break; |
604 | 606 | ||
607 | case 'K': | ||
608 | opts |= OPT_K; | ||
609 | break; | ||
610 | |||
605 | case 1: | 611 | case 1: |
606 | if (!src_fn) { | 612 | if (!src_fn) { |
607 | /* The zip file */ | 613 | /* The zip file */ |
@@ -819,7 +825,10 @@ int unzip_main(int argc, char **argv) | |||
819 | # endif | 825 | # endif |
820 | if ((cdf.fmt.version_made_by >> 8) == 3) { | 826 | if ((cdf.fmt.version_made_by >> 8) == 3) { |
821 | /* This archive is created on Unix */ | 827 | /* This archive is created on Unix */ |
822 | dir_mode = file_mode = (cdf.fmt.external_attributes >> 16); | 828 | file_mode = (cdf.fmt.external_attributes >> 16); |
829 | if (!(opts & OPT_K)) | ||
830 | file_mode &= ~(mode_t)(S_ISUID | S_ISGID); | ||
831 | dir_mode = file_mode; | ||
823 | } | 832 | } |
824 | } | 833 | } |
825 | #endif | 834 | #endif |