| [c5c522c] | 1 | From: Ben Hutchings <ben@decadent.org.uk> |
|---|
| 2 | Date: Fri, 18 Sep 2015 21:59:17 +0200 |
|---|
| 3 | Subject: gzip: Fix silent fallback to decompression |
|---|
| 4 | Bug-Debian: https://bugs.debian.org/355809 |
|---|
| 5 | Forwarded: http://www.zytor.com/pipermail/klibc/2016-January/003892.html |
|---|
| 6 | |
|---|
| 7 | If the gzip utilities are built without support for compression, |
|---|
| 8 | they will always attempt to carry out decompression even if the |
|---|
| 9 | command name and options don't imply that. Instead they should |
|---|
| 10 | fail with an explicit error in this case. |
|---|
| 11 | |
|---|
| 12 | Signed-off-by: Ben Hutchings <ben@decadent.org.uk> |
|---|
| 13 | --- |
|---|
| 14 | --- a/usr/gzip/gzip.c |
|---|
| 15 | +++ b/usr/gzip/gzip.c |
|---|
| 16 | @@ -90,8 +90,11 @@ int level = 6; /* compression lev |
|---|
| 17 | #endif |
|---|
| 18 | |
|---|
| 19 | int to_stdout; /* output to stdout (-c) */ |
|---|
| 20 | -#ifndef decompress |
|---|
| 21 | +#ifdef decompress |
|---|
| 22 | +int decompress_wanted; |
|---|
| 23 | +#else |
|---|
| 24 | int decompress; /* decompress (-d) */ |
|---|
| 25 | +#define decompress_wanted decompress |
|---|
| 26 | #endif |
|---|
| 27 | int force; /* don't ask questions, compress links (-f) */ |
|---|
| 28 | int no_name = -1; /* don't save or restore the original file name */ |
|---|
| 29 | @@ -259,17 +262,13 @@ int main (argc, argv) |
|---|
| 30 | * Systems which do not support links can still use -d or -dc. |
|---|
| 31 | * Ignore an .exe extension for MSDOS, OS/2 and VMS. |
|---|
| 32 | */ |
|---|
| 33 | -#ifndef decompress |
|---|
| 34 | if ( strncmp(progname, "un", 2) == 0 /* ungzip, uncompress */ |
|---|
| 35 | || strncmp(progname, "gun", 3) == 0) { /* gunzip */ |
|---|
| 36 | - decompress = 1; |
|---|
| 37 | + decompress_wanted = 1; |
|---|
| 38 | } |
|---|
| 39 | -#endif |
|---|
| 40 | if (strequ(progname+1, "cat") /* zcat, pcat, gcat */ |
|---|
| 41 | || strequ(progname, "gzcat")) { /* gzcat */ |
|---|
| 42 | -#ifndef decompress |
|---|
| 43 | - decompress = 1; |
|---|
| 44 | -#endif |
|---|
| 45 | + decompress_wanted = 1; |
|---|
| 46 | to_stdout = 1; |
|---|
| 47 | } |
|---|
| 48 | #endif |
|---|
| 49 | @@ -282,9 +281,7 @@ int main (argc, argv) |
|---|
| 50 | case 'c': |
|---|
| 51 | to_stdout = 1; break; |
|---|
| 52 | case 'd': |
|---|
| 53 | -#ifndef decompress |
|---|
| 54 | - decompress = 1; |
|---|
| 55 | -#endif |
|---|
| 56 | + decompress_wanted = 1; |
|---|
| 57 | break; |
|---|
| 58 | case 'f': |
|---|
| 59 | force++; break; |
|---|
| 60 | @@ -308,9 +305,7 @@ int main (argc, argv) |
|---|
| 61 | break; |
|---|
| 62 | case 't': |
|---|
| 63 | test = to_stdout = 1; |
|---|
| 64 | -#ifndef decompress |
|---|
| 65 | - decompress = 1; |
|---|
| 66 | -#endif |
|---|
| 67 | + decompress_wanted = 1; |
|---|
| 68 | break; |
|---|
| 69 | case 'v': |
|---|
| 70 | verbose++; quiet = 0; break; |
|---|
| 71 | @@ -329,6 +324,14 @@ int main (argc, argv) |
|---|
| 72 | } |
|---|
| 73 | } /* loop on all arguments */ |
|---|
| 74 | |
|---|
| 75 | +#ifndef SUPPORT_ZIP |
|---|
| 76 | + if (!decompress_wanted) { |
|---|
| 77 | + fprintf(stderr, "%s: this version does not support compression\n", |
|---|
| 78 | + progname); |
|---|
| 79 | + do_exit(ERROR); |
|---|
| 80 | + } |
|---|
| 81 | +#endif |
|---|
| 82 | + |
|---|
| 83 | /* By default, save name and timestamp on compression but do not |
|---|
| 84 | * restore them on decompression. |
|---|
| 85 | */ |
|---|