Prevent memory exhaustion from a corrupt PE binary with an overlarge number of relocs.
authorNick Clifton <nickc@redhat.com>
Tue, 2 May 2017 10:54:53 +0000 (11:54 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 2 May 2017 10:54:53 +0000 (11:54 +0100)
PR 21440
* objdump.c (dump_relocs_in_section): Check for an excessive
number of relocs before attempting to dump them.

binutils/ChangeLog
binutils/objdump.c

index ae8defb4dd300d29f158a4c5c31698ce9566bbaf..5fdcd4dd77763a21d65c2febce255eb6570bb1bd 100644 (file)
@@ -1,3 +1,9 @@
+2017-05-02  Nick Clifton  <nickc@redhat.com>
+
+       PR 21440
+       * objdump.c (dump_relocs_in_section): Check for an excessive
+       number of relocs before attempting to dump them.
+
 2017-05-01  Alan Modra  <amodra@gmail.com>
 
        * objcopy.c (merge_gnu_build_notes): Correct code deleting
index bc610003a7dc85faa9f42a70fd1237a8ffcb29fc..5972da1d4e027c0942125ccc54567d4af117ca68 100644 (file)
@@ -3379,6 +3379,14 @@ dump_relocs_in_section (bfd *abfd,
       return;
     }
 
+  if ((bfd_get_file_flags (abfd) & (BFD_IN_MEMORY | BFD_LINKER_CREATED)) == 0
+      && relsize > get_file_size (bfd_get_filename (abfd)))
+    {
+      printf (" (too many: 0x%x)\n", section->reloc_count);
+      bfd_set_error (bfd_error_file_truncated);
+      bfd_fatal (bfd_get_filename (abfd));
+    }
+
   relpp = (arelent **) xmalloc (relsize);
   relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);