public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] elf_begin sets elf_errno for cases that the file is completely unreadable
@ 2014-09-11 18:49 Petr Machata
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Machata @ 2014-09-11 18:49 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 634 bytes --]

Roland McGrath <roland@hack.frob.com> writes:

>>    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;
>> +    {
>> +      __libelf_seterrno (ELF_E_INVALID_FILE);
>> +      /* 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;
>> +    }
>
> That looks sensible, though I'd keep the comment at the top of the block.

Pushed with that fix.

Thanks,
PM

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

* Re: [PATCH] elf_begin sets elf_errno for cases that the file is completely unreadable
@ 2014-09-10 20:36 Roland McGrath
  0 siblings, 0 replies; 3+ messages in thread
From: Roland McGrath @ 2014-09-10 20:36 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

>    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;
> +    {
> +      __libelf_seterrno (ELF_E_INVALID_FILE);
> +      /* 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;
> +    }

That looks sensible, though I'd keep the comment at the top of the block.

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

* [PATCH] elf_begin sets elf_errno for cases that the file is completely unreadable
@ 2014-09-10 20:25 Petr Machata
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Machata @ 2014-09-10 20:25 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

- 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   |    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  <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.
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 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;
+    {
+      __libelf_seterrno (ELF_E_INVALID_FILE);
+      /* 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;
+    }
 
   /* See what kind of object we have here.  */
   Elf_Kind kind = determine_kind (mem.header, nread);
-- 
1.7.6.5


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

end of thread, other threads:[~2014-09-11 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11 18:49 [PATCH] elf_begin sets elf_errno for cases that the file is completely unreadable Petr Machata
  -- strict thread matches above, loose matches on Subject: below --
2014-09-10 20:36 Roland McGrath
2014-09-10 20:25 Petr Machata

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).