public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: [PATCH] readelf: Skip section if name is NULL in print_debug.
Date: Tue, 27 May 2014 10:28:16 +0200	[thread overview]
Message-ID: <1401179296-12115-1-git-send-email-mjw@redhat.com> (raw)

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

Don't crash and burn when a section doesn't have a name (possibly invalid
ELF file string table). Just try the next section instead of calling strcmp
on NULL.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog |    4 ++++
 src/readelf.c |    4 +++-
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 5535cff..7e68036 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2014-05-27  Mark Wielaard  <mjw@redhat.com>
+
+	* readelf.c (print_debug): Skip section if name is NULL.
+
 2014-05-26  Mark Wielaard  <mjw@redhat.com>
 
 	* readelf.c (handle_relocs_rela): Print header like handle_relocs_rel
diff --git a/src/readelf.c b/src/readelf.c
index ea14a09..6bbe436 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -7962,8 +7962,10 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr)
 				       / sizeof (debug_sections[0]));
 	  const char *name = elf_strptr (ebl->elf, shstrndx,
 					 shdr->sh_name);
-	  int n;
+	  if (name == NULL)
+	    continue;
 
+	  int n;
 	  for (n = 0; n < ndebug_sections; ++n)
 	    if (strcmp (name, debug_sections[n].name) == 0
 #if USE_ZLIB
-- 
1.7.1


             reply	other threads:[~2014-05-27  8:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-27  8:28 Mark Wielaard [this message]
2014-06-03 11:54 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=1401179296-12115-1-git-send-email-mjw@redhat.com \
    --to=mjw@redhat.com \
    --cc=elfutils-devel@lists.fedorahosted.org \
    /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).