Fix a crash with a malformed PE header
authorJon Turney <jon.turney@dronecode.org.uk>
Thu, 2 Jan 2020 00:25:56 +0000 (00:25 +0000)
committerJon Turney <jon.turney@dronecode.org.uk>
Mon, 6 Jan 2020 18:30:44 +0000 (18:30 +0000)
Don't try to read the PE export table when no section contains the RVA
for it.

(I have a PE executable [1] packed with UPX, where the export table data
directory entry contains a RVA which doesn't correspond to any section.
Mistakenly trying to debug this with gdb makes it crash.)

[1] https://cygwin.com/setup/setup-2.898.x86_64.exe

gdb/ChangeLog:

2020-01-02  Jon Turney  <jon.turney@dronecode.org.uk>

* coff-pe-read.c (read_pe_exported_syms): Don't try to read the
export table if no section contains it's RVA.

gdb/ChangeLog
gdb/coff-pe-read.c

index 177b50542ef7c927bd29aaba6ad0bc211e5ebe68..9a3cca2a127a0dc6b4ef94429ed154ef5e708459 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-02  Jon Turney  <jon.turney@dronecode.org.uk>
+
+       * coff-pe-read.c (read_pe_exported_syms): Don't try to read the
+       export table if no section contains it's RVA.
+
 2020-01-06  Eli Zaretskii  <eliz@gnu.org>
 
        * windows-tdep.c: Fix a typo in WINDOWS_SIGABRT.
index e1c51d45e382c0d8a8eebe4ab0fd662e0836f978..d0c1e050c891fbc438f6550ff66ad97748724d5d 100644 (file)
@@ -441,6 +441,12 @@ read_pe_exported_syms (minimal_symbol_reader &reader,
        }
     }
 
+  if (expptr == 0)
+    {
+      /* no section contains export table rva */
+      return;
+    }
+
   export_rva = export_opthdrrva;
   export_size = export_opthdrsize;