From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============2983865239492517302==" MIME-Version: 1.0 From: Petr Machata To: elfutils-devel@lists.fedorahosted.org Subject: [PATCH] elf_begin sets elf_errno for cases that the file is completely unreadable Date: Wed, 10 Sep 2014 22:25:35 +0200 Message-ID: <25b4c5f3c6b5c513f6c8b2c9da199f9cd02e6be8.1410380644.git.pmachata@redhat.com> --===============2983865239492517302== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable - The problem this is trying to solve can be seen for example thus: $ eu-readelf -a / eu-readelf: failed reading '/': (null) With the fix we see a proper error number and get a reasonable error message: $ eu-readelf -a / eu-readelf: failed reading '/': invalid file descriptor Signed-off-by: Petr Machata --- libelf/ChangeLog | 5 +++++ libelf/elf_begin.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 4bc8f56..5ad20a6 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2014-09-10 Petr Machata + + * elf_begin (read_unmmaped_file): Call __libelf_seterrno if the + file is unreadable. + 2014-07-07 Mark Wielaard = * elf.h: Update from glibc. diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index 1ef70ac..3ee195d 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -550,9 +550,12 @@ read_unmmaped_file (int fildes, off_t offset, size_t m= axsize, Elf_Cmd cmd, maxsize), offset); if (unlikely (nread =3D=3D -1)) - /* We cannot even read the head of the file. Maybe FILDES is associat= ed - with an unseekable device. This is nothing we can handle. */ - return NULL; + { + __libelf_seterrno (ELF_E_INVALID_FILE); + /* We cannot even read the head of the file. Maybe FILDES is associ= ated + with an unseekable device. This is nothing we can handle. */ + return NULL; + } = /* See what kind of object we have here. */ Elf_Kind kind =3D determine_kind (mem.header, nread); -- = 1.7.6.5 --===============2983865239492517302==--