Andreas Mohr wrote:

Hi,

On Mon, Aug 29, 2005 at 01:43:04PM -0500, Alex Villací­s Lasso wrote:
I could not find any MSDN reference on any documented behavior for LoadLibrary16 or LoadModule16 when libname == NULL.

I've checked it now (Watcom, Win98 SE):

(forgot to zero LOADPARAMS, sorry! But it hopefully didn't matter...)

a) NULL, &lp                0 "system out of mem/executable corrupt/relocs 
invalid"
b) "kernel", NULL     kernel handle
c) NULL, NULL           0
d) (char *)0x1, &lp 2 "file not found"
e) (char *)0x1256, NULL 2
f) NULL, (void *)0x1257 0

NO CRASHES whatsoever, IOW it fully intercepts any invalid pointers.

a), c), f) vs. d) indicates that it does an explicit check against a NULL name,
since probably otherwise LoadModule16 will continue due to the non-NULL
name (0x1) and notice somewhat later (in some file API) that file name 0x1
is invalid.
The attached patch should implement the observed behavior in Win98SE.

Alex Villacís Lasso

Changelog:
- Add NULL and exception handler to LoadModule16 to check against NULL or invalid libname

--- wine-20050830-cvs/dlls/kernel/ne_module.c	2005-07-22 10:36:40.000000000 -0500
+++ wine-20050830-cvs-patch/dlls/kernel/ne_module.c	2005-09-01 00:18:26.000000000 -0500
@@ -1197,6 +1197,20 @@
     LPSTR cmdline;
     WORD cmdShow;
 
+    if (name == NULL) return 0;
+    __TRY
+    {
+        /* Cause walk through name - should trigger page fault if invalid */
+        unsigned int iDummy = strlen(name);
+        iDummy = iDummy;
+    }
+    __EXCEPT(page_fault)
+    {
+        /* Invalid pointer to module name */
+        return ERROR_FILE_NOT_FOUND;
+    }
+    __ENDTRY
+
     /* Load module */
 
     if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )


Reply via email to