From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117034 invoked by alias); 27 Feb 2017 22:55:40 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 116997 invoked by uid 48); 27 Feb 2017 22:55:34 -0000 From: "jistone at redhat dot com" To: elfutils-devel@sourceware.org Subject: [Bug general/21203] New: Poor error handling for archives with non-ELF members Date: Mon, 27 Feb 2017 22:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: elfutils X-Bugzilla-Component: general X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jistone at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2017-q1/txt/msg00089.txt.bz2 https://sourceware.org/bugzilla/show_bug.cgi?id=3D21203 Bug ID: 21203 Summary: Poor error handling for archives with non-ELF members Product: elfutils Version: unspecified Status: NEW Severity: normal Priority: P2 Component: general Assignee: unassigned at sourceware dot org Reporter: jistone at redhat dot com CC: elfutils-devel at sourceware dot org Target Milestone: --- Elfutils doesn't seem to behave well when it encounters non-ELF objects in = an archive. As an easy example, a Rust *.rlib contains both ELF *.o and non-E= LF metadata and bytecode. $ eu-readelf -h /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-*.rlib eu-readelf: cannot stat input file: Bad file descriptor For comparison, binutils prints errors about the unrecognized objects, but still provides useful output for the rest. $ readelf -h /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-*.rlib [...] File: /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-570da8f8.rlib(rust.met= adata.bin) readelf: Error: Not an ELF file - it has the wrong magic bytes at the start File: /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-570da8f8.rlib(std-570d= a8f8.0.bytecode.deflate) readelf: Error: Not an ELF file - it has the wrong magic bytes at the start This particular archive has 13 ELF and those 2 non-ELF members. With strac= e, I can see 13 close(4) calls in a row, followed by the fstat(4,...) that leads= to "cannot stat input file". Then there's yet another close(4)=3DEBADF, *afte= r* that file descriptor was already momentarily re-used for locale purposes. open("/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-570da8f8.rlib", O_RDONLY) =3D 3 dup(3) =3D 4 fcntl(4, F_GETFL) =3D 0x8000 (flags O_RDONLY|O_LARGEF= ILE) fstat(4, {st_mode=3DS_IFREG|0644, st_size=3D12447250, ...}) =3D 0 mmap(NULL, 12447250, PROT_READ|PROT_WRITE, MAP_PRIVATE, 4, 0) =3D 0x7fc8577= ba000 mmap(NULL, 692224, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = =3D 0x7fc85fcae000 close(4) =3D 0 close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) close(4) =3D -1 EBADF (Bad file descriptor) fstat(4, 0x7ffd45ce0630) =3D -1 EBADF (Bad file descriptor) open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) =3D 4 fstat(4, {st_mode=3DS_IFREG|0644, st_size=3D2502, ...}) =3D 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =3D 0x7fc85fd6c000 read(4, "# Locale name alias data base.\n#"..., 4096) =3D 2502 read(4, "", 4096) =3D 0 close(4) =3D 0 munmap(0x7fc85fd6c000, 4096) =3D 0 open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/elfutils.mo", O_RDONLY) =3D= -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US.utf8/LC_MESSAGES/elfutils.mo", O_RDONLY) =3D = -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US/LC_MESSAGES/elfutils.mo", O_RDONLY) =3D -1 EN= OENT (No such file or directory) open("/usr/share/locale/en.UTF-8/LC_MESSAGES/elfutils.mo", O_RDONLY) =3D -1 ENOENT (No such file or directory) open("/usr/share/locale/en.utf8/LC_MESSAGES/elfutils.mo", O_RDONLY) =3D -1 = ENOENT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/elfutils.mo", O_RDONLY) =3D -1 ENOEN= T (No such file or directory) write(2, "eu-readelf: ", 12eu-readelf: ) =3D 12 write(2, "cannot stat input file", 22cannot stat input file) =3D 22 open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 = ENOENT (No such file or directory) open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 E= NOENT (No such file or directory) open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 ENOENT= (No such file or directory) open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 ENO= ENT (No such file or directory) open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 ENOE= NT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 ENOENT (N= o such file or directory) write(2, ": Bad file descriptor", 21: Bad file descriptor) =3D 21 write(2, "\n", 1 ) =3D 1 close(4) =3D -1 EBADF (Bad file descriptor) munmap(0x7fc85fcae000, 692224) =3D 0 close(3) =3D 0 exit_group(1) =3D ? +++ exited with 1 +++ --=20 You are receiving this mail because: You are on the CC list for the bug.