gendef segfaults when running on OpenWatcom-built dlls.
With something simple as this:
$ cat 1.c void __declspec(dllexport) foo(void) {} $ wcc386 -bt=nt -bd -3s -q 1.c $ wlink NAM 1.dll SYSTEM nt_dll FIL {1.o} [...] $ gdb --args ./gendef 1.dll [...] Starting program: /home/sezero/gendef/gendef 1.dll * [1.dll] Found PE image * export directory at VA = 0xb000 size=0x3e Program received signal SIGSEGV, Segmentation fault. 0x080499ad in do_export_read (va_exp=45056, sz_exp=62, be64=0) at src/gendef.c:570 570 fndllname = strdup ((char *) map_va (exp_dir->Name)); (gdb) bt #0 0x080499ad in do_export_read (va_exp=45056, sz_exp=62, be64=0) at src/gendef.c:570 #1 0x08049709 in do_pedef () at src/gendef.c:478 #2 0x08048df6 in main (argc=2, argv=0xbfb0e3d4) at src/gendef.c:231
The example 1.dll is attached.
Obviously map_va() returns NULL for exp_dir and exp_dir->Name
becomes a NULL pointer dereference. Now, why do we get NULL from
map_va()..
Kai?
P.S.: Curiously, the pexports tool from mingw.org woks fine with these dlls.
No idea. Sadly I don't have time to look into this. Debugging map_va doesn't reveal here anything?
Kai:
Some sections seem to have Misc.VirtualSize==0, therefore map_va()
skips them and when there are none left it returns NULL.
I made a patch (inlined below, also attached) so if Misc.VirtualSize
is zero it would use SizeOfRawData instead. With this, gendef does
not crash and generates the def.
Comments? Is the patch correct?
Patch looks sensible to me. Please go ahead and apply it to master.
I guess this fix will be something for open branches, too.
Thanks,
Kai
2017-03-07 13:29 GMT+01:00 Ozkan Sezer sezero@users.sf.net:
Patch applied to master and all branches. Closing as fixed.