commit:     9daf7217a29e8542ad80672a3b82ae1b8c497321
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 13 08:59:13 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jul 13 08:59:13 2015 +0000
URL:        https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=9daf7217

scanelf: do not warn about invalid archive entries by default

It's not uncommon for embedded toolchains or random targets to create
their own spin on the archive format.  Rather than complain about all
of these by default, put it behind the -v flag.  It's not like people
can do anything about this normally anyways.

URL: https://bugs.gentoo.org/428464

 paxinc.c    | 12 ++++++++----
 paxinc.h    |  5 +++--
 scanelf.c   |  2 +-
 scanmacho.c |  2 +-
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/paxinc.c b/paxinc.c
index f2ce3c5..64a7f3b 100644
--- a/paxinc.c
+++ b/paxinc.c
@@ -17,7 +17,7 @@ char do_reverse_endian;
 
 #define AR_MAGIC "!<arch>"
 #define AR_MAGIC_SIZE (sizeof(AR_MAGIC)-1) /* dont count null byte */
-archive_handle *ar_open_fd(const char *filename, int fd)
+archive_handle *ar_open_fd(const char *filename, int fd, bool verbose)
 {
        static archive_handle ret;
        char buf[AR_MAGIC_SIZE];
@@ -26,6 +26,7 @@ archive_handle *ar_open_fd(const char *filename, int fd)
        ret.fd = fd;
        ret.skip = 0;
        ret.extfn = NULL;
+       ret.verbose = verbose;
 
        if (read(ret.fd, buf, AR_MAGIC_SIZE) != AR_MAGIC_SIZE)
                return NULL;
@@ -34,7 +35,7 @@ archive_handle *ar_open_fd(const char *filename, int fd)
 
        return &ret;
 }
-archive_handle *ar_open(const char *filename)
+archive_handle *ar_open(const char *filename, bool verbose)
 {
        int fd;
        archive_handle *ret;
@@ -42,7 +43,7 @@ archive_handle *ar_open(const char *filename)
        if ((fd=open(filename, O_RDONLY)) == -1)
                errp("%s: could not open", filename);
 
-       ret = ar_open_fd(filename, fd);
+       ret = ar_open_fd(filename, fd, verbose);
        if (ret == NULL)
                close(fd);
 
@@ -76,7 +77,10 @@ close_and_ret:
        }
 
        if ((ret.buf.formatted.magic[0] != '`') || (ret.buf.formatted.magic[1] 
!= '\n')) {
-               warn("%s: invalid ar entry", ar->filename);
+               /* When dealing with corrupt or random embedded 
cross-compilers, they might
+                * be abusing the archive format; only complain when in verbose 
mode. */
+               if (ar->verbose)
+                       warn("%s: invalid ar entry", ar->filename);
                goto close_and_ret;
        }
 

diff --git a/paxinc.h b/paxinc.h
index 003877d..0a8e08a 100644
--- a/paxinc.h
+++ b/paxinc.h
@@ -37,6 +37,7 @@ typedef struct {
        const char *filename;
        size_t skip;
        char *extfn;
+       bool verbose;
 } archive_handle;
 #else
 typedef void archive_handle;
@@ -63,8 +64,8 @@ typedef struct {
        } buf;
 #endif
 } archive_member;
-archive_handle *ar_open_fd(const char *filename, int fd);
-archive_handle *ar_open(const char *filename);
+archive_handle *ar_open_fd(const char *filename, int fd, bool verbose);
+archive_handle *ar_open(const char *filename, bool verbose);
 archive_member *ar_next(archive_handle *);
 
 const char *strfileperms(const char *fname);

diff --git a/scanelf.c b/scanelf.c
index 7219f1c..82ab626 100644
--- a/scanelf.c
+++ b/scanelf.c
@@ -1717,7 +1717,7 @@ static int scanelf_archive(const char *filename, int fd, 
size_t len)
        char *ar_buffer;
        elfobj *elf;
 
-       ar = ar_open_fd(filename, fd);
+       ar = ar_open_fd(filename, fd, be_verbose);
        if (ar == NULL)
                return 1;
 

diff --git a/scanmacho.c b/scanmacho.c
index a36aed4..f8c4d89 100644
--- a/scanmacho.c
+++ b/scanmacho.c
@@ -383,7 +383,7 @@ static int scanmacho_archive(const char *filename, int fd, 
size_t len)
        fatobj *fobj;
        fatobj *walk;
 
-       ar = ar_open_fd(filename, fd);
+       ar = ar_open_fd(filename, fd, be_verbose);
        if (ar == NULL)
                return 1;
 

Reply via email to