elf_begin sets elf_errno for cases that the file is completely unreadable
authorPetr Machata <pmachata@redhat.com>
Wed, 10 Sep 2014 20:25:35 +0000 (22:25 +0200)
committerPetr Machata <pmachata@redhat.com>
Thu, 11 Sep 2014 17:45:11 +0000 (19:45 +0200)
- 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 <pmachata@redhat.com>
libelf/ChangeLog
libelf/elf_begin.c

index 4bc8f56..5ad20a6 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-10  Petr Machata  <pmachata@redhat.com>
+
+       * elf_begin (read_unmmaped_file): Call __libelf_seterrno if the
+       file is unreadable.
+
 2014-07-07  Mark Wielaard  <mjw@redhat.com>
 
        * elf.h: Update from glibc.
index 1ef70ac..c3ad140 100644 (file)
@@ -550,9 +550,12 @@ read_unmmaped_file (int fildes, off_t offset, size_t maxsize, Elf_Cmd cmd,
                                    maxsize),
                               offset);
   if (unlikely (nread == -1))
-    /* We cannot even read the head of the file.  Maybe FILDES is associated
-       with an unseekable device.  This is nothing we can handle.  */
-    return NULL;
+    {
+      /* We cannot even read the head of the file.  Maybe FILDES is associated
+        with an unseekable device.  This is nothing we can handle.  */
+      __libelf_seterrno (ELF_E_INVALID_FILE);
+      return NULL;
+    }
 
   /* See what kind of object we have here.  */
   Elf_Kind kind = determine_kind (mem.header, nread);