[binutils-gdb] Prevent memory exhaustion from a corrupt PE binary with an overlarge number of relocs.

Nick Clifton nickc@sourceware.org
Tue May 2 10:55:00 GMT 2017


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=39ff1b79f687b65f4144ddb379f22587003443fb

commit 39ff1b79f687b65f4144ddb379f22587003443fb
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue May 2 11:54:53 2017 +0100

    Prevent memory exhaustion from a corrupt PE binary with an overlarge number of relocs.
    
    	PR 21440
    	* objdump.c (dump_relocs_in_section): Check for an excessive
    	number of relocs before attempting to dump them.

Diff:
---
 binutils/ChangeLog | 6 ++++++
 binutils/objdump.c | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index ae8defb..5fdcd4d 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -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
diff --git a/binutils/objdump.c b/binutils/objdump.c
index bc61000..5972da1 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -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);



More information about the Binutils-cvs mailing list