public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug general/21203] New: Poor error handling for archives with non-ELF members
@ 2017-02-27 22:55 jistone at redhat dot com
  2017-02-27 22:59 ` [Bug general/21203] " jistone at redhat dot com
  0 siblings, 1 reply; 2+ messages in thread
From: jistone at redhat dot com @ 2017-02-27 22:55 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=21203

            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-ELF
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.metadata.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-570da8f8.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 strace, 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)=EBADF, *after*
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) = 3
dup(3)                                  = 4
fcntl(4, F_GETFL)                       = 0x8000 (flags O_RDONLY|O_LARGEFILE)
fstat(4, {st_mode=S_IFREG|0644, st_size=12447250, ...}) = 0
mmap(NULL, 12447250, PROT_READ|PROT_WRITE, MAP_PRIVATE, 4, 0) = 0x7fc8577ba000
mmap(NULL, 692224, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7fc85fcae000
close(4)                                = 0
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
close(4)                                = -1 EBADF (Bad file descriptor)
fstat(4, 0x7ffd45ce0630)                = -1 EBADF (Bad file descriptor)
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=2502, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7fc85fd6c000
read(4, "# Locale name alias data base.\n#"..., 4096) = 2502
read(4, "", 4096)                       = 0
close(4)                                = 0
munmap(0x7fc85fd6c000, 4096)            = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/elfutils.mo", O_RDONLY) = -1
ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/elfutils.mo", O_RDONLY) = -1
ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/elfutils.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/elfutils.mo", O_RDONLY) = -1
ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/elfutils.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/elfutils.mo", O_RDONLY) = -1 ENOENT (No
such file or directory)
write(2, "eu-readelf: ", 12eu-readelf: )            = 12
write(2, "cannot stat input file", 22cannot stat input file)  = 22
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such
file or directory)
write(2, ": Bad file descriptor", 21: Bad file descriptor)   = 21
write(2, "\n", 1
)                       = 1
close(4)                                = -1 EBADF (Bad file descriptor)
munmap(0x7fc85fcae000, 692224)          = 0
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug general/21203] Poor error handling for archives with non-ELF members
  2017-02-27 22:55 [Bug general/21203] New: Poor error handling for archives with non-ELF members jistone at redhat dot com
@ 2017-02-27 22:59 ` jistone at redhat dot com
  0 siblings, 0 replies; 2+ messages in thread
From: jistone at redhat dot com @ 2017-02-27 22:59 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=21203

--- Comment #1 from Josh Stone <jistone at redhat dot com> ---
Actually, the repeated close(4) seems to be a more general problem.  I see this
even for a more typical archive, like my libz.a with 15 objects sees 15 EBADF.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-27 22:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 22:55 [Bug general/21203] New: Poor error handling for archives with non-ELF members jistone at redhat dot com
2017-02-27 22:59 ` [Bug general/21203] " jistone at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).