public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [COMMITTED] size: Robustify against gelf_getshdr returning NULL.
@ 2019-04-28 16:05 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2019-04-28 16:05 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 7 +++++++
 src/size.c    | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3020bd768..e3e411ef5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2019-04-28  Mark Wielaard  <mark@klomp.org>
+
+	* size.c (show_sysv): Call INTERNAL_ERROR if gelf_getshdr
+	returns NULL.
+	(show_sysv_one_line): Call error with EXIT_FAILURE if
+	gelf_getshdr returns NULL.
+
 2019-04-28  Mark Wielaard  <mark@klomp.org>
 
 	* nm.c (show_symbols_sysv): Check gelf_getshdr doesn't return
diff --git a/src/size.c b/src/size.c
index f01fd880c..a25d4471f 100644
--- a/src/size.c
+++ b/src/size.c
@@ -428,6 +428,9 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
       GElf_Shdr shdr_mem;
       GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
 
+      if (shdr == NULL)
+	INTERNAL_ERROR (fullname);
+
       /* Ignore all sections which are not used at runtime.  */
       if ((shdr->sh_flags & SHF_ALLOC) != 0)
 	{
@@ -475,6 +478,9 @@ show_sysv_one_line (Elf *elf)
       GElf_Shdr shdr_mem;
       GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
 
+      if (unlikely (shdr == NULL))
+	error (EXIT_FAILURE, 0, gettext ("cannot get section header"));
+
       /* Ignore all sections which are not used at runtime.  */
       if ((shdr->sh_flags & SHF_ALLOC) == 0)
 	continue;
-- 
2.20.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-28 16:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28 16:05 [COMMITTED] size: Robustify against gelf_getshdr returning NULL 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).