From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Josh Stone <jistone@redhat.com>, Mark Wielaard <mark@klomp.org>
Subject: [PATCH 2/2] libelf: Don't error out when sanity checking e_shoff if scncnt is zero.
Date: Wed, 04 Oct 2017 18:57:00 -0000 [thread overview]
Message-ID: <1507143449-19288-2-git-send-email-mark@klomp.org> (raw)
In-Reply-To: <1507143449-19288-1-git-send-email-mark@klomp.org>
We won't use the e_shoff value in that case because we will set
elf->state.elf[64|32].scns.cnt to zero to indicate not to read
any section header data from the file.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libelf/ChangeLog | 5 +++++
libelf/elf_begin.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 36b57dd..6aa1c6f 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,10 @@
2017-10-04 Mark Wielaard <mark@klomp.org>
+ * elf_begin.c (file_read_elf): Skip sanity checking e_shoff if scncnt
+ is zero, we won't use it then.
+
+2017-10-04 Mark Wielaard <mark@klomp.org>
+
* libelfP.h: Add ELF_E_INVALID_ELF to error values enum.
* elf_error.c (ELF_E_INVALID_ELF_IDX): New define. Use it as value
for ELF_E_INVALID_ELF in msgidx.
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 5545278..fb3a5b5 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -373,7 +373,7 @@ file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
|| (((uintptr_t) ((char *) ehdr + e_shoff)
& (__alignof__ (Elf32_Shdr) - 1)) == 0)))
{
- if (unlikely (e_shoff >= maxsize)
+ if (unlikely (scncnt > 0 && e_shoff >= maxsize)
|| unlikely (maxsize - e_shoff
< scncnt * sizeof (Elf32_Shdr)))
{
@@ -475,7 +475,7 @@ file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
|| (((uintptr_t) ((char *) ehdr + e_shoff)
& (__alignof__ (Elf64_Shdr) - 1)) == 0)))
{
- if (unlikely (e_shoff >= maxsize)
+ if (unlikely (scncnt > 0 && e_shoff >= maxsize)
|| unlikely (maxsize - e_shoff
< scncnt * sizeof (Elf64_Shdr)))
goto free_and_out;
--
1.8.3.1
next prev parent reply other threads:[~2017-10-04 18:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-28 19:06 failed reading "Smallest x86 ELF Hello World" Josh Stone
2017-10-04 18:55 ` Mark Wielaard
2017-10-04 18:57 ` [PATCH 1/2] libelf: Add ELF_E_INVALID_ELF error value Mark Wielaard
2017-10-04 18:57 ` Mark Wielaard [this message]
2017-10-13 15:09 ` failed reading "Smallest x86 ELF Hello World" Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1507143449-19288-2-git-send-email-mark@klomp.org \
--to=mark@klomp.org \
--cc=elfutils-devel@sourceware.org \
--cc=jistone@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).