This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] readelf: prevent segfault


Sometimes, e.g. when malformed ELF file, the ebl_dynamic_tag_name() 
returns NULL which causes puts() to segfault immediately without
ceremony.  Fixed thusly.  Tested on x86_64.  Ok for trunk?

Signed-off-by: Marek Polacek <mpolacek@redhat.com>
---
 src/ChangeLog |    4 ++++
 src/readelf.c |    6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 6ba890f..66cca15 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2011-03-22  Marek Polacek  <mpolacek@redhat.com>
+
+	* readelf.c (handle_dynamic): Don't segfault at DT_PLTREL case.
+
 2011-03-10  Mark Wielaard  <mjw@redhat.com>
 
 	* elflint.c (check_symtab): Use ebl_check_st_other_bits.
diff --git a/src/readelf.c b/src/readelf.c
index 956d8bd..2e149b2 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1445,8 +1445,10 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
 	  printf ("%" PRId64 "\n", dyn->d_un.d_val);
 	  break;
 
-	case DT_PLTREL:
-	  puts (ebl_dynamic_tag_name (ebl, dyn->d_un.d_val, NULL, 0));
+	case DT_PLTREL:;
+	  const char *tagname = ebl_dynamic_tag_name (ebl, dyn->d_un.d_val,
+						      NULL, 0);
+	  puts (tagname ?: "???");
 	  break;
 
 	case DT_FLAGS:
-- 
1.7.3.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]