LoadLibrary should ignore trailing spaces in the library name.

This commit is contained in:
Vitaliy Margolen 2005-10-18 14:10:56 +00:00 committed by Alexandre Julliard
parent c0cd7dc6fa
commit 64896241b8
2 changed files with 30 additions and 6 deletions

View File

@ -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;
}
/***********************************************************************

View File

@ -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);
}