From 64896241b863927794b7acadaa7067f411c039e1 Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Tue, 18 Oct 2005 14:10:56 +0000 Subject: [PATCH] LoadLibrary should ignore trailing spaces in the library name. --- dlls/kernel/module.c | 16 +++++++++++++++- dlls/kernel/tests/module.c | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dlls/kernel/module.c b/dlls/kernel/module.c index b901ecab91a..80de15a370b 100644 --- a/dlls/kernel/module.c +++ b/dlls/kernel/module.c @@ -833,6 +833,7 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) HMODULE WINAPI LoadLibraryExW(LPCWSTR libnameW, HANDLE hfile, DWORD flags) { UNICODE_STRING wstr; + HMODULE res; if (!libnameW) { @@ -840,7 +841,20 @@ HMODULE WINAPI LoadLibraryExW(LPCWSTR libnameW, HANDLE hfile, DWORD flags) 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; } /*********************************************************************** diff --git a/dlls/kernel/tests/module.c b/dlls/kernel/tests/module.c index 97d7788843a..c8d65cc7616 100644 --- a/dlls/kernel/tests/module.c +++ b/dlls/kernel/tests/module.c @@ -103,18 +103,28 @@ static void testGetModuleFileName_Wrong(void) 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); }