* coffcode.h (coff_slurp_line_table): Warn about illegal symbol
authorIan Lance Taylor <ian@airs.com>
Tue, 17 Sep 1996 18:20:06 +0000 (18:20 +0000)
committerIan Lance Taylor <ian@airs.com>
Tue, 17 Sep 1996 18:20:06 +0000 (18:20 +0000)
indices, rather than crashing.
(coff_slurp_reloc_table): Likewise.  Check whether the howto field
is NULL.

bfd/ChangeLog
bfd/coffcode.h

index 5718b14616268384087dc1c551eec4dc11990b5b..4bac85b3341bdf90af6822a60859af3fe2a7a357 100644 (file)
@@ -1,3 +1,10 @@
+Tue Sep 17 14:18:31 1996  Ian Lance Taylor  <ian@cygnus.com>
+
+       * coffcode.h (coff_slurp_line_table): Warn about illegal symbol
+       indices, rather than crashing.
+       (coff_slurp_reloc_table): Likewise.  Check whether the howto field
+       is NULL.
+
 Mon Sep 16 12:39:36 1996  Ian Lance Taylor  <ian@cygnus.com>
 
        * coff-arm.c (aoutarm_std_reloc_howto): Change dst_mask for ARM26D
index 8de83a543b73ef244b156a68c2968c2c50de2890..508f75e0639b561e5ade2d03eb4651145fe513af 100644 (file)
@@ -2986,7 +2986,7 @@ coff_set_section_contents (abfd, section, location, offset, count)
   if (abfd->output_has_begun == false) /* set by bfd.c handler */
     coff_compute_section_file_positions (abfd);
 
-#ifdef _LIB
+#if defined(_LIB) && !defined(TARG_AUX)
 
    /* The physical address field of a .lib section is used to hold the
       number of shared libraries in the section.  This code counts the
@@ -3138,11 +3138,27 @@ coff_slurp_line_table (abfd, asect)
 
          if (cache_ptr->line_number == 0)
            {
-             coff_symbol_type *sym =
-             (coff_symbol_type *) (dst.l_addr.l_symndx
-                     + obj_raw_syments (abfd))->u.syment._n._n_n._n_zeroes;
+             boolean warned;
+             long symndx;
+             coff_symbol_type *sym;
+
+             warned = false;
+             symndx = dst.l_addr.l_symndx;
+             if (symndx < 0 || symndx >= obj_raw_syment_count (abfd))
+               {
+                 (*_bfd_error_handler)
+                   ("%s: warning: illegal symbol index %ld in line numbers",
+                    bfd_get_filename (abfd), dst.l_addr.l_symndx);
+                 symndx = 0;
+                 warned = true;
+               }
+             /* FIXME: We should not be casting between ints and
+                 pointers like this.  */
+             sym = ((coff_symbol_type *)
+                    ((symndx + obj_raw_syments (abfd))
+                     ->u.syment._n._n_n._n_zeroes));
              cache_ptr->u.sym = (asymbol *) sym;
-             if (sym->lineno != NULL)
+             if (sym->lineno != NULL && ! warned)
                {
                  (*_bfd_error_handler)
                    ("%s: warning: duplicate line number information for `%s'",
@@ -3604,11 +3620,20 @@ coff_slurp_reloc_table (abfd, asect, symbols)
 
       if (dst.r_symndx != -1)
        {
-         /* @@ Should never be greater than count of symbols!  */
-         if (dst.r_symndx >= obj_conv_table_size (abfd))
-           abort ();
-         cache_ptr->sym_ptr_ptr = symbols + obj_convert (abfd)[dst.r_symndx];
-         ptr = *(cache_ptr->sym_ptr_ptr);
+         if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
+           {
+             (*_bfd_error_handler)
+               ("%s: warning: illegal symbol index %ld in relocs",
+                bfd_get_filename (abfd), dst.r_symndx);
+             cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
+             ptr = 0;
+           }
+         else
+           {
+             cache_ptr->sym_ptr_ptr = (symbols
+                                       + obj_convert (abfd)[dst.r_symndx]);
+             ptr = *(cache_ptr->sym_ptr_ptr);
+           }
        }
       else
        {
@@ -3633,6 +3658,13 @@ coff_slurp_reloc_table (abfd, asect, symbols)
       RTYPE2HOWTO (cache_ptr, &dst);
 #endif
 
+      if (cache_ptr->howto == NULL)
+       {
+         (*_bfd_error_handler)
+           ("%s: illegal relocation type %d at address 0x%lx",
+            bfd_get_filename (abfd), dst.r_type, (long) dst.r_vaddr);
+         return false;
+       }
     }
 
   asect->relocation = reloc_cache;