Fix a crash with a malformed PE header

Message ID 20200102125405.11499-1-jon.turney@dronecode.org.uk
State New, archived
Headers

Commit Message

Jon Turney Jan. 2, 2020, 12:54 p.m. UTC
  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      | 5 +++++
 gdb/coff-pe-read.c | 6 ++++++
 2 files changed, 11 insertions(+)
  

Comments

Eli Zaretskii Jan. 2, 2020, 1:56 p.m. UTC | #1
> From: Jon Turney <jon.turney@dronecode.org.uk>
> Cc: Jon Turney <jon.turney@dronecode.org.uk>
> Date: Thu,  2 Jan 2020 12:54:05 +0000
> 
> --- a/gdb/coff-pe-read.c
> +++ b/gdb/coff-pe-read.c
> @@ -441,6 +441,12 @@ read_pe_exported_syms (minimal_symbol_reader &reader,
>  	}
>      }
>  
> +  if (expptr == 0)
> +    {
> +      /* no section contains export table rva */
> +      return;
> +    }
> +

Thanks.  Would it make sense to produce some diagnostic output here,
when an appropriate debug-FOO option is set?
  

Patch

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index b05357bb8b..305900cfa3 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -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;