Fix lossage due to pathname truncation in calls to MODULE_LoadLibraryExA

Michael Beach michaelb at ieee.org
Thu Sep 12 05:38:09 CDT 2002


Recently I've been using WINE to run a Win32 exe which needs to load certain 
DLLs which are located in the same directory as the exe. I was most perplexed 
when I found that this worked initially, but when I moved the exe and DLLs to 
a different directory it stopped working ie WINE would refuse to start the 
exe, claiming that it was unable to load the required DLLs.

After some debugging, I discovered that the critical factor was the length of 
the pathname to the exe, when it passed a certain length it stopped working. 
However this length was way short of the MAX_PATH value of 260.

More investigation showed that in DIR_TryModulePath the path name that was 
being built for the DLL was being limited to OFS_MAXPATHNAME, which clearly 
was too short for the pathname of the module in question, and judging by the 
comment was a holdover from pre-Win32 WINE code. So switched to using 
MAX_PATH instead of OFS_MAXPATHNAME to size the name buffers in 
DIR_TryModulePath, and the problem I was seeing went away.

I can't state with 100% certainty that there isn't some problem with this 
change that I have overlooked (this is my first bit of spelunking in the WINE 
source after all), but to the best of my knowledge it is ok.

Regards
M.Beach
-------------- next part --------------
? DIR_TryModulePath-patch.diff
Index: files/directory.c
===================================================================
RCS file: /home/wine/wine/files/directory.c,v
retrieving revision 1.51
diff -u -r1.51 directory.c
--- files/directory.c	27 Aug 2002 01:13:59 -0000	1.51
+++ files/directory.c	12 Sep 2002 10:16:55 -0000
@@ -716,9 +716,7 @@
  */
 static BOOL DIR_TryModulePath( LPCWSTR name, DOS_FULL_NAME *full_name, BOOL win32 )
 {
-    /* FIXME: for now, GetModuleFileNameW can't return more */
-    /* than OFS_MAXPATHNAME. This may change with Win32. */
-    WCHAR bufferW[OFS_MAXPATHNAME];
+    WCHAR bufferW[MAX_PATH];
     LPWSTR p;
 
     if (!win32)
@@ -727,13 +725,13 @@
 	if (!GetCurrentTask()) return FALSE;
 	if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) ))
             return FALSE;
-        MultiByteToWideChar(CP_ACP, 0, buffer, -1, bufferW, OFS_MAXPATHNAME);
+        MultiByteToWideChar(CP_ACP, 0, buffer, -1, bufferW, MAX_PATH);
     } else {
-	if (!GetModuleFileNameW( 0, bufferW, OFS_MAXPATHNAME ) )
+	if (!GetModuleFileNameW( 0, bufferW, MAX_PATH ) )
             return FALSE;
     }
     if (!(p = strrchrW( bufferW, '\\' ))) return FALSE;
-    if (OFS_MAXPATHNAME - (++p - bufferW) <= strlenW(name)) return FALSE;
+    if (MAX_PATH - (++p - bufferW) <= strlenW(name)) return FALSE;
     strcpyW( p, name );
     return DOSFS_GetFullName( bufferW, TRUE, full_name );
 }


More information about the wine-patches mailing list