Fix an access through a null pointer when parsing a corrupt SOM format fle.
authorNick Clifton <nickc@redhat.com>
Thu, 29 Apr 2021 16:55:43 +0000 (17:55 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 29 Apr 2021 16:55:43 +0000 (17:55 +0100)
PR 27793
* som.c (som_slurp_symbol_table): Assign symbols without any scope
to the undefined section.
(som_decode_symclass): Check for a missing symbol section.
* syms.c (bfd_decode_symclass): Likewise.

bfd/ChangeLog
bfd/som.c
bfd/syms.c

index 3144a72d21d524da2dc8c163ac35914f0e62c7c9..4bdee1cb1235289814f862770595e8d4554a3114 100644 (file)
@@ -1,3 +1,11 @@
+2021-04-29  Nick Clifton  <nickc@redhat.com>
+
+       PR 27793
+       * som.c (som_slurp_symbol_table): Assign symbols without any scope
+       to the undefined section.
+       (som_decode_symclass): Check for a missing symbol section.
+       * syms.c (bfd_decode_symclass): Likewise.
+
 2021-04-29  Nick Clifton  <nickc@redhat.com>
 
        PR 27792
index 656ded96b697197e00c78a964a3bc10edaa5ff27..42ecc765945b802824b355a133d5d5abefe29712 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -4740,7 +4740,7 @@ som_slurp_symbol_table (bfd *abfd)
          goto error_return;
        }
       sym->symbol.value = bfd_getb32 (bufp->symbol_value);
-      sym->symbol.section = 0;
+      sym->symbol.section = NULL;
       sym->symbol.flags = 0;
 
       switch (symbol_type)
@@ -4800,6 +4800,10 @@ som_slurp_symbol_table (bfd *abfd)
          sym->symbol.section = bfd_section_from_som_symbol (abfd, bufp);
          sym->symbol.value -= sym->symbol.section->vma;
          break;
+
+       default:
+         sym->symbol.section = bfd_und_section_ptr;
+         break;
        }
 
       /* Check for a weak symbol.  */
@@ -5848,6 +5852,11 @@ som_decode_symclass (asymbol *symbol)
 {
   char c;
 
+  /* If the symbol did not have a scope specified,
+     then it will not have associated section.  */
+  if (symbol == NULL || symbol->section == NULL)
+    return '?';
+
   if (bfd_is_com_section (symbol->section))
     return 'C';
   if (bfd_is_und_section (symbol->section))
index e0ab16795d64b72ba804ccb51f0b4eed88ca5623..7daf741b7b61e27db12e04226599979226cc1f21 100644 (file)
@@ -654,6 +654,10 @@ bfd_decode_symclass (asymbol *symbol)
 {
   char c;
 
+  /* Paranoia...  */
+  if (symbol == NULL || symbol->section == NULL)
+    return '?';
+
   if (symbol->section && bfd_is_com_section (symbol->section))
     {
       if (symbol->section->flags & SEC_SMALL_DATA)