This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Patch]: ld crash on i386/pe when linking with a dll that has no exports
- From: Tristan Gingold <gingold at adacore dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Wed, 25 Nov 2009 10:20:54 +0100
- Subject: [Patch]: ld crash on i386/pe when linking with a dll that has no exports
Hi,
we got a crash when linking with a dll whose export directory is empty:
...
NumberOfRvaAndSizes 00000010
The Data Directory
Entry 0 00000000 00000000 Export Directory [.edata (or where ever we found it)]
Entry 1 00016000 0000003c Import Directory [parts of .idata]
...
In fact there is no guard against such values in ld/pe-dll.c(pe_implied_import_dll) and this function
assumes that the export directory entry is not empty if present.
This patch fixes this crash.
(I think we may add consistency checks - such as checking the minimum length of the export directory)
Tristan.
ld/
2009-11-25 Tristan Gingold <gingold@adacore.com>
* pe-dll.c (pe_implied_import_dll): Return early if there is no
export entries.
*** ld/pe-dll.c 15 Nov 2009 07:52:42 -0000 1.123
--- ld/pe-dll.c 25 Nov 2009 09:12:43 -0000
***************
*** 3001,3006 ****
--- 3001,3010 ----
export_size = pe_get32 (dll, opthdr_ofs + 100);
#endif
+ /* No exports. */
+ if (export_size == 0)
+ return FALSE;
+
nsections = pe_get16 (dll, pe_header_offset + 4 + 2);
secptr = (pe_header_offset + 4 + 20 +
pe_get16 (dll, pe_header_offset + 4 + 16));