More fixes for illegal memory accesses triggered by running objdump on fuzzed binaries.
[deliverable/binutils-gdb.git] / bfd / elf32-xgate.c
index 588901bab11c7373cf1613b1d8b0f390e247c617..4c416b3010daf17028f5529d285413163ae80ce7 100644 (file)
@@ -1,5 +1,5 @@
 /* Freescale XGATE-specific support for 32-bit ELF
-   Copyright (C) 2010-2014 Free Software Foundation, Inc.
+   Copyright (C) 2010-2015 Free Software Foundation, Inc.
    Contributed by Sean Keys(skeys@ipdatasys.com)
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -52,8 +52,8 @@ static reloc_howto_type elf_xgate_howto_table[] =
   /* This reloc does nothing.  */
   HOWTO (R_XGATE_NONE, /* type */
         0, /* rightshift */
-        2, /* size (0 = byte, 1 = short, 2 = long) */
-        32, /* bitsize */
+        3, /* size (0 = byte, 1 = short, 2 = long) */
+        0, /* bitsize */
         FALSE, /* pc_relative */
         0, /* bitpos */
         complain_overflow_dont,/* complain_on_overflow */
@@ -422,24 +422,28 @@ xgate_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   unsigned int r_type;
 
   r_type = ELF32_R_TYPE (dst->r_info);
-  BFD_ASSERT(r_type < (unsigned int) R_XGATE_max);
+  if (r_type >= (unsigned int) R_XGATE_max)
+    {
+      _bfd_error_handler (_("%B: invalid XGate reloc number: %d"), abfd, r_type);
+      r_type = 0;
+    }
   cache_ptr->howto = &elf_xgate_howto_table[r_type];
 }
 
-/* Free the derived linker hash table.  */
+/* Destroy an XGATE ELF linker hash table.  */
 
-void
-xgate_elf_bfd_link_hash_table_free (struct bfd_link_hash_table *hash)
+static void
+xgate_elf_bfd_link_hash_table_free (bfd *obfd)
 {
   struct xgate_elf_link_hash_table *ret =
-      (struct xgate_elf_link_hash_table *) hash;
+      (struct xgate_elf_link_hash_table *) obfd->link.hash;
 
   bfd_hash_table_free (ret->stub_hash_table);
   free (ret->stub_hash_table);
-  _bfd_elf_link_hash_table_free (hash);
+  _bfd_elf_link_hash_table_free (obfd);
 }
 
-/* Create a XGATE ELF linker hash table.  */
+/* Create an XGATE ELF linker hash table.  */
 
 static struct bfd_link_hash_table*
 xgate_elf_bfd_link_hash_table_create (bfd *abfd)
@@ -464,7 +468,7 @@ xgate_elf_bfd_link_hash_table_create (bfd *abfd)
   ret->stub_hash_table = (struct bfd_hash_table*) bfd_zmalloc (amt);
   if (ret->stub_hash_table == NULL)
     {
-      free (ret);
+      _bfd_elf_link_hash_table_free (abfd);
       return NULL;
     }
 
@@ -472,9 +476,10 @@ xgate_elf_bfd_link_hash_table_create (bfd *abfd)
       sizeof(struct elf32_xgate_stub_hash_entry)))
     {
       free (ret->stub_hash_table);
-      free (ret);
+      _bfd_elf_link_hash_table_free (abfd);
       return NULL;
     }
+  ret->root.root.hash_table_free = xgate_elf_bfd_link_hash_table_free;
 
   return &ret->root.root;
 }
This page took 0.02571 seconds and 4 git commands to generate.