[PATCH 1/2] pe/coff: Avoid a crash using objdump -p on the output of objcopy --only-keep-debug

Jon TURNEY jon.turney@dronecode.org.uk
Tue Mar 18 14:39:00 GMT 2014


Avoid a crash when using objdump -p on the output of objcopy --only-keep-debug

e.g.

$ objdump -p /usr/lib/debug/usr/bin/cygwin1.dbg
[...]
The Export Tables (interpreted .edata section contents)

Export Flags                    0
Time/Date stamp                 0
Major/Minor                     0/0
Segmentation fault (core dumped)

Verfify that edt.name lies inside the .edata section we have loaded before
dereferencing it.  Change adj to to bfd_vma to avoid signed vs. unsigned
comparison warnings - it could only be negative if a section had a negative
vma.

bfd/Changelog:

2014-03-18  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* peXXigen.c (pe_print_edata): Verify edt.name lies inside
	section before dereferencing.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 bfd/peXXigen.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 8219ab9..d011c0e 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -1373,7 +1373,7 @@ pe_print_edata (bfd * abfd, void * vfile)
   bfd_size_type datasize = 0;
   bfd_size_type dataoff;
   bfd_size_type i;
-  bfd_signed_vma adj;
+  bfd_vma adj;
   struct EDT_type
   {
     long export_flags;          /* Reserved - should be zero.  */
@@ -1478,8 +1478,12 @@ pe_print_edata (bfd * abfd, void * vfile)
   fprintf (file,
 	   _("Name \t\t\t\t"));
   bfd_fprintf_vma (abfd, file, edt.name);
-  fprintf (file,
+
+  if ((edt.name >= adj) && (edt.name < adj + datasize))
+    fprintf (file,
 	   " %s\n", data + edt.name - adj);
+  else
+    fprintf (file, "(outside .edata section)\n");
 
   fprintf (file,
 	   _("Ordinal Base \t\t\t%ld\n"), edt.base);
-- 
1.8.3.4



More information about the Binutils mailing list