tar: fix too eager autodetection, closes 11531
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 27 Nov 2018 10:26:48 +0000 (11:26 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 27 Nov 2018 10:26:48 +0000 (11:26 +0100)
function                                             old     new   delta
is_suffixed_with                                       -      54     +54
tar_main                                            1006    1026     +20
open_transformer                                      92      79     -13
config_file_action                                   478     458     -20
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 74/-33)             Total: 41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/libarchive/open_transformer.c
archival/tar.c
modutils/modprobe.c

index 9fefd4aaddcc99371de275c3d35dc0ace39cbe79..4a4bf391683ec904152e9219c52152d5b18ee39e 100644 (file)
@@ -278,8 +278,7 @@ static transformer_state_t *open_transformer(const char *fname, int fail_if_not_
 
        if (ENABLE_FEATURE_SEAMLESS_LZMA) {
                /* .lzma has no header/signature, can only detect it by extension */
-               char *sfx = strrchr(fname, '.');
-               if (sfx && strcmp(sfx+1, "lzma") == 0) {
+               if (is_suffixed_with(fname, ".lzma")) {
                        xstate = xzalloc(sizeof(*xstate));
                        xstate->src_fd = fd;
                        xstate->xformer = unpack_lzma_stream;
index 1c71f7f661a8176e84086d46de8ea2a6f2de0297..6950c271d7d441ef1f74588802b9082ff7173b82 100644 (file)
@@ -1162,8 +1162,16 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
                        tar_handle->seek = seek_by_read;
                } else
                if (ENABLE_FEATURE_TAR_AUTODETECT
+                && ENABLE_FEATURE_SEAMLESS_LZMA
                 && flags == O_RDONLY
                 && !(opt & OPT_ANY_COMPRESS)
+                && is_suffixed_with(tar_filename, ".lzma")
+               /* We do this only for .lzma files, they have no signature.
+                * All other compression formats are recognized in
+                * get_header_tar() when first tar block has invalid format.
+                * Doing it here for all filenames would falsely trigger
+                * on e.g. tarball with 1st file named "BZh5".
+                */
                ) {
                        tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
                        if (tar_handle->src_fd < 0)
index 59f6d54f371a8d1ef2bd0eae6fde299f6dc05a53..291e4cb906aa03d66a52b21c65a762ed5d4db2db 100644 (file)
@@ -245,7 +245,7 @@ static int FAST_FUNC config_file_action(const char *filename,
        parser_t *p;
        struct module_entry *m;
        int rc = TRUE;
-       const char *base, *ext;
+       const char *base;
 
        /* Skip files that begin with a "." */
        base = bb_basename(filename);
@@ -266,8 +266,7 @@ static int FAST_FUNC config_file_action(const char *filename,
         * "include FILE_NOT_ENDING_IN_CONF" must work too.
         */
        if (depth != 0) {
-               ext = strrchr(base, '.');
-               if (ext == NULL || strcmp(ext + 1, "conf"))
+               if (!is_suffixed_with(base, ".conf"))
                        goto error;
        }