kernel: Try2: Fix [Bug:1885] - LoadLibraryA("name ")

Vitaliy Margolen wine-patch at kievinfo.com
Mon Oct 17 09:56:15 CDT 2005


Don't duplicate string if library name has no trailing spaces.

What's interesting this works only on winnt+. Win9x gives error
ERROR_DLL_NOT_FOUND.
I've ran some tests to find where it does this. It's done in the kernel32 not
ntdll. And ntdll fails in the same way as wine's does.

Vitaliy Margolen

changelog:
  kernel:
  - LoadLibrary should ignore trailing spaces in the library name.
-------------- next part --------------
Index: dlls/kernel/module.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/module.c,v
retrieving revision 1.19
diff -u -p -r1.19 module.c
--- dlls/kernel/module.c	22 Sep 2005 10:44:40 -0000	1.19
+++ dlls/kernel/module.c	17 Oct 2005 14:53:00 -0000
@@ -833,6 +833,7 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR lib
 HMODULE WINAPI LoadLibraryExW(LPCWSTR libnameW, HANDLE hfile, DWORD flags)
 {
     UNICODE_STRING      wstr;
+    HMODULE             res;
 
     if (!libnameW)
     {
@@ -840,7 +841,20 @@ HMODULE WINAPI LoadLibraryExW(LPCWSTR li
         return 0;
     }
     RtlInitUnicodeString( &wstr, libnameW );
-    return load_library( &wstr, flags );
+    if (wstr.Buffer[wstr.Length/sizeof(WCHAR) - 1] != ' ')
+        return load_library( &wstr, flags );
+
+    /* Library name has trailing spaces */
+    RtlCreateUnicodeString( &wstr, libnameW );
+    while (wstr.Length > sizeof(WCHAR) &&
+           wstr.Buffer[wstr.Length/sizeof(WCHAR) - 1] == ' ')
+    {
+        wstr.Length -= sizeof(WCHAR);
+    }
+    wstr.Buffer[wstr.Length/sizeof(WCHAR)] = '\0';
+    res = load_library( &wstr, flags );
+    RtlFreeUnicodeString( &wstr );
+    return res;
 }
 
 /***********************************************************************
Index: dlls/kernel/tests/module.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/module.c,v
retrieving revision 1.6
diff -u -p -r1.6 module.c
--- dlls/kernel/tests/module.c	1 Aug 2005 10:57:04 -0000	1.6
+++ dlls/kernel/tests/module.c	10 Oct 2005 21:05:38 -0000
@@ -103,18 +103,28 @@ static void testGetModuleFileName_Wrong(
 
 static void testLoadLibraryA(void)
 {
-    HMODULE hModule;
+    HMODULE hModule, hModule1;
     FARPROC fp;
 
     SetLastError(0xdeadbeef);
-    hModule = LoadLibraryA("ntdll.dll");
-    ok( hModule != NULL, "ntdll.dll should be loadable\n");
+    hModule = LoadLibraryA("kernel32.dll");
+    ok( hModule != NULL, "kernel32.dll should be loadable\n");
     ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %08lx\n", GetLastError());
 
-    fp = GetProcAddress(hModule, "NtCreateFile"); 
-    ok( fp != NULL, "Call should be there\n");
+    fp = GetProcAddress(hModule, "CreateFileA");
+    ok( fp != NULL, "CreateFileA should be there\n");
     ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %08lx\n", GetLastError());
 
+    SetLastError(0xdeadbeef);
+    hModule1 = LoadLibraryA("kernel32   ");
+    /* Only winNT does this */
+    if (GetLastError() != ERROR_DLL_NOT_FOUND)
+    {
+        ok( hModule1 != NULL, "\"kernel32   \" should be loadable\n");
+        ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %08lx\n", GetLastError());
+        ok( hModule == hModule1, "Loaded wrong module\n");
+        FreeLibrary(hModule1);
+    }
     FreeLibrary(hModule);
 }
 


More information about the wine-patches mailing list