Fixes for memory access violations triggered by running nlmconv on
authorNick Clifton <nickc@redhat.com>
Thu, 8 Jan 2015 12:37:46 +0000 (12:37 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 8 Jan 2015 12:37:46 +0000 (12:37 +0000)
fuzzed binaries.

PR binutils/17512
* nlmconv.c (i386_mangle_relocs): Skip relocs without an
associated symbol.
(powerpc_mangle_relocs): Skip unrecognised relocs.  Check address
range before applying a reloc.

binutils/ChangeLog
binutils/nlmconv.c

index 17d2dd670dbce88e9fcc4edad42bf027a215bd10..cfad0f764271e7a982e826b00ee415a690794278 100644 (file)
@@ -1,3 +1,11 @@
+2015-01-08  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/17512
+       * nlmconv.c (i386_mangle_relocs): Skip relocs without an
+       associated symbol.
+       (powerpc_mangle_relocs): Skip unrecognised relocs.  Check address
+       range before applying a reloc.
+
 2015-01-07  Nick Clifton  <nickc@redhat.com>
 
        PR binutils/17512
index d0db1b3045292485d0643f9bd25a38155c191b28..8c4975df979c81cf3517706bbeed3cb73100a134 100644 (file)
@@ -1415,6 +1415,9 @@ i386_mangle_relocs (bfd *outbfd, asection *insec, arelent ***relocs_ptr,
       bfd_vma addend;
 
       rel = *relocs++;
+      /* PR 17512: file: 057f89c1.  */
+      if (rel->sym_ptr_ptr == NULL)
+       continue;
       sym = *rel->sym_ptr_ptr;
 
       /* We're moving the relocs from the input section to the output
@@ -1871,7 +1874,7 @@ powerpc_mangle_relocs (bfd *outbfd, asection *insec,
 
   toc_howto = bfd_reloc_type_lookup (insec->owner, BFD_RELOC_PPC_TOC16);
   if (toc_howto == (reloc_howto_type *) NULL)
-    abort ();
+    fatal (_("Unable to locate PPC_TOC16 reloc information"));
 
   /* If this is the .got section, clear out all the contents beyond
      the initial size.  We must do this here because copy_sections is
@@ -1910,6 +1913,10 @@ powerpc_mangle_relocs (bfd *outbfd, asection *insec,
            }
        }
 
+      /* PR 17512: file: 70cfde95.  */
+      if (rel->howto == NULL)
+       continue;
+
       /* We must be able to resolve all PC relative relocs at this
         point.  If we get a branch to an undefined symbol we build a
         stub, since NetWare will resolve undefined symbols into a
@@ -1927,6 +1934,12 @@ powerpc_mangle_relocs (bfd *outbfd, asection *insec,
            {
              bfd_vma val;
 
+             if (rel->address > contents_size - 4)
+               {
+                 non_fatal (_("Out of range relocation: %lx"), rel->address);
+                 break;
+               }
+             
              assert (rel->howto->size == 2 && rel->howto->pcrel_offset);
              val = bfd_get_32 (outbfd, (bfd_byte *) contents + rel->address);
              val = ((val &~ rel->howto->dst_mask)
@@ -1976,6 +1989,12 @@ powerpc_mangle_relocs (bfd *outbfd, asection *insec,
          switch (rel->howto->size)
            {
            case 1:
+             if (rel->address > contents_size - 2)
+               {
+                 non_fatal (_("Out of range relocation: %lx"), rel->address);
+                 break;
+               }
+                      
              val = bfd_get_16 (outbfd,
                                (bfd_byte *) contents + rel->address);
              val = ((val &~ rel->howto->dst_mask)
@@ -1991,6 +2010,13 @@ powerpc_mangle_relocs (bfd *outbfd, asection *insec,
              break;
 
            case 2:
+             /* PR 17512: file: 0455a112.  */
+             if (rel->address > contents_size - 4)
+               {
+                 non_fatal (_("Out of range relocation: %lx"), rel->address);
+                 break;
+               }
+                      
              val = bfd_get_32 (outbfd,
                                (bfd_byte *) contents + rel->address);
              val = ((val &~ rel->howto->dst_mask)
@@ -2002,7 +2028,7 @@ powerpc_mangle_relocs (bfd *outbfd, asection *insec,
              break;
 
            default:
-             abort ();
+             fatal (_("Unsupported relocation size: %d"), rel->howto->size);
            }
 
          if (! bfd_is_und_section (bfd_get_section (sym)))
This page took 0.041412 seconds and 4 git commands to generate.