From 0d9d816fc352a556f1d00fde5a5e0e52e35e1ddb Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 5 Jun 2019 21:01:34 +0200 Subject: [PATCH] kernel32: Fix handling of LOAD_WITH_ALTERED_SEARCH_PATH when other search flags are specified. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46809 Signed-off-by: Alexandre Julliard --- dlls/kernel32/module.c | 13 +++++++++++-- dlls/kernel32/tests/module.c | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c index 1ea7b0e942a..386a7c22399 100644 --- a/dlls/kernel32/module.c +++ b/dlls/kernel32/module.c @@ -941,11 +941,20 @@ static HMODULE load_library( const UNICODE_STRING *libname, DWORD flags ) const DWORD unsupported_flags = (LOAD_IGNORE_CODE_AUTHZ_LEVEL | LOAD_LIBRARY_REQUIRE_SIGNED_TARGET); - if (!(flags & load_library_search_flags)) flags |= default_search_flags; - if( flags & unsupported_flags) FIXME("unsupported flag(s) used (flags: 0x%08x)\n", flags); + if (flags & LOAD_WITH_ALTERED_SEARCH_PATH) + { + if (flags & load_library_search_flags) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + if (default_search_flags) flags |= default_search_flags | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR; + } + else if (!(flags & load_library_search_flags)) flags |= default_search_flags; + if (flags & load_library_search_flags) load_path = get_dll_load_path_search_flags( libname->Buffer, flags ); else diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c index c059b988bf9..a8cdc3d3df1 100644 --- a/dlls/kernel32/tests/module.c +++ b/dlls/kernel32/tests/module.c @@ -565,6 +565,31 @@ static void test_LoadLibraryEx_search_flags(void) mod = LoadLibraryExA( path, 0, LOAD_LIBRARY_SEARCH_SYSTEM32 ); ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() ); FreeLibrary( mod ); + + SetLastError( 0xdeadbeef ); + mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_WITH_ALTERED_SEARCH_PATH ); + ok( !mod, "LoadLibrary succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_WITH_ALTERED_SEARCH_PATH ); + ok( !mod, "LoadLibrary succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_WITH_ALTERED_SEARCH_PATH ); + ok( !mod, "LoadLibrary succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_WITH_ALTERED_SEARCH_PATH ); + ok( !mod, "LoadLibrary succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_USER_DIRS | LOAD_WITH_ALTERED_SEARCH_PATH ); + ok( !mod, "LoadLibrary succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); } SetCurrentDirectoryA( curdir );