[binutils-gdb] Prevent a seg-fault from objdup when disassembling binaries which do not contain a symbol table.

Nick Clifton nickc@sourceware.org
Wed Jun 12 14:06:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=62e0492f5723dd3db5e5a48a3a0ac161d7ba2701

commit 62e0492f5723dd3db5e5a48a3a0ac161d7ba2701
Author: Adam Lackorzymski <adam@os.inf.tu-dresden.de>
Date:   Wed Jun 12 15:05:21 2019 +0100

    Prevent a seg-fault from objdup when disassembling binaries which do not contain a symbol table.
    
    	PR 24643
    	* elf32-arm.c (arm_elf_find_function): Fail if the symol table is
    	absent, or the bfd is not in the ELF formart.
    	* elfnn-aarch64.c (aarch64_elf_find_function): Likewise.

Diff:
---
 bfd/ChangeLog       |  7 +++++++
 bfd/elf32-arm.c     | 10 ++++++++--
 bfd/elfnn-aarch64.c | 20 +++++++++++++-------
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 72f35b8..b31e798 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2019-06-12  Adam Lackorzymski  <adam@os.inf.tu-dresden.de>
+
+	PR 24643
+	* elf32-arm.c (arm_elf_find_function): Fail if the symol table is
+	absent, or the bfd is not in the ELF formart.
+	* elfnn-aarch64.c (aarch64_elf_find_function): Likewise.
+
 2019-06-10  Christos Zoulas  <christos@zoulas.com>
 
 	PR 24650
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index d35d609..52fd48f 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -15983,12 +15983,12 @@ elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
 					 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
 }
 
-/* This is a copy of elf_find_function() from elf.c except that
+/* This is a version of _bfd_elf_find_function() from dwarf2.c except that
    ARM mapping symbols are ignored when looking for function names
    and STT_ARM_TFUNC is considered to a function type.  */
 
 static bfd_boolean
-arm_elf_find_function (bfd *	     abfd ATTRIBUTE_UNUSED,
+arm_elf_find_function (bfd *	     abfd,
 		       asymbol **    symbols,
 		       asection *    section,
 		       bfd_vma	     offset,
@@ -16000,6 +16000,12 @@ arm_elf_find_function (bfd *	     abfd ATTRIBUTE_UNUSED,
   bfd_vma low_func = 0;
   asymbol ** p;
 
+  if (symbols == NULL)
+    return FALSE;
+
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+    return FALSE;
+
   for (p = symbols; *p != NULL; p++)
     {
       elf_symbol_type *q;
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 282418d..e33a5c6 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -7956,22 +7956,28 @@ elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
 					     BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
 }
 
-/* This is a copy of elf_find_function () from elf.c except that
+/* This is a version of _bfd_elf_find_function() from dwarf2.c except that
    AArch64 mapping symbols are ignored when looking for function names.  */
 
 static bfd_boolean
-aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
-			   asymbol **symbols,
-			   asection *section,
-			   bfd_vma offset,
-			   const char **filename_ptr,
-			   const char **functionname_ptr)
+aarch64_elf_find_function (bfd *          abfd,
+			   asymbol **     symbols,
+			   asection *     section,
+			   bfd_vma        offset,
+			   const char **  filename_ptr,
+			   const char **  functionname_ptr)
 {
   const char *filename = NULL;
   asymbol *func = NULL;
   bfd_vma low_func = 0;
   asymbol **p;
 
+  if (symbols == NULL)
+    return FALSE;
+
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+    return FALSE;
+
   for (p = symbols; *p != NULL; p++)
     {
       elf_symbol_type *q;



More information about the Binutils-cvs mailing list