public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libelf: Check header exists in elf_strptr
@ 2020-11-01 18:46 Mark Wielaard
  2020-11-06 17:49 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2020-11-01 18:46 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

We already checked the header actually existed for ELFCLASS64 but not
for the ELFCLASS32 case. It is very unlikely it is at this point in the
code, but theoretically it could happen.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libelf/ChangeLog    | 4 ++++
 libelf/elf_strptr.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index aee1ffff..db3eed08 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2020-11-01  Mark Wielaard  <mark@klomp.org>
+
+	* elf_strptr.c (elf_strptr): Check shdr is not NULL.
+
 2020-11-01  Mark Wielaard  <mark@klomp.org>
 
 	* elf_getphdrnum.c (__elf_getphdrnum_rdlock): Set *dst to zero on
diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c
index c7271707..76f2caf1 100644
--- a/libelf/elf_strptr.c
+++ b/libelf/elf_strptr.c
@@ -119,7 +119,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
   if (elf->class == ELFCLASS32)
     {
       Elf32_Shdr *shdr = strscn->shdr.e32 ?: __elf32_getshdr_rdlock (strscn);
-      if (unlikely (shdr->sh_type != SHT_STRTAB))
+      if (unlikely (shdr == NULL || shdr->sh_type != SHT_STRTAB))
 	{
 	  /* This is no string section.  */
 	  __libelf_seterrno (ELF_E_INVALID_SECTION);
-- 
2.18.4


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

* Re: [PATCH] libelf: Check header exists in elf_strptr
  2020-11-01 18:46 [PATCH] libelf: Check header exists in elf_strptr Mark Wielaard
@ 2020-11-06 17:49 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2020-11-06 17:49 UTC (permalink / raw)
  To: elfutils-devel

On Sun, 2020-11-01 at 19:46 +0100, Mark Wielaard wrote:
> We already checked the header actually existed for ELFCLASS64 but not
> for the ELFCLASS32 case. It is very unlikely it is at this point in the
> code, but theoretically it could happen.

Pushed.

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

end of thread, other threads:[~2020-11-06 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01 18:46 [PATCH] libelf: Check header exists in elf_strptr Mark Wielaard
2020-11-06 17:49 ` Mark Wielaard

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