objdump segfault after symbol table error

Message ID ZA/WoJ/0CrDmzojB@squeak.grove.modra.org
State Repeat Merge
Headers
Series objdump segfault after symbol table error |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Alan Modra March 14, 2023, 2:06 a.m. UTC
  This memcpy segfaults if symcount is -1 (=> syms is NULL).
      memcpy (sorted_syms, symcount ? syms : dynsyms,
	      sorted_symcount * sizeof (asymbol *));

	* objdump.c (slurp_symtab): Don't leave symcount as -1 after
	an error.
	(slurp_dynamic_symtab): Likewise for dynsymcount.
  

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 0e8e1980b80..5dac13ba868 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1015,6 +1015,7 @@  slurp_symtab (bfd *abfd)
       my_bfd_nonfatal (bfd_get_filename (abfd));
       free (sy);
       sy = NULL;
+      symcount = 0;
     }
   return sy;
 }
@@ -1048,6 +1049,7 @@  slurp_dynamic_symtab (bfd *abfd)
       my_bfd_nonfatal (bfd_get_filename (abfd));
       free (sy);
       sy = NULL;
+      dynsymcount = 0;
     }
   return sy;
 }