Alexandre Julliard : ntdll: Don' t use current directory for libraries unless explicitly specified in the search path.
Alexandre Julliard
julliard at winehq.org
Wed Feb 6 15:32:28 CST 2019
Module: wine
Branch: master
Commit: 6fb00db51e21914e57b2c4ea04b1a95081425d48
URL: https://source.winehq.org/git/wine.git/?a=commit;h=6fb00db51e21914e57b2c4ea04b1a95081425d48
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Feb 6 10:45:18 2019 +0100
ntdll: Don't use current directory for libraries unless explicitly specified in the search path.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/kernel32/tests/module.c | 84 ++++++++++++++++++++++++++++++++++++++++++--
dlls/ntdll/loader.c | 12 ++-----
2 files changed, 84 insertions(+), 12 deletions(-)
diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
index ba65e0a..2314c84 100644
--- a/dlls/kernel32/tests/module.c
+++ b/dlls/kernel32/tests/module.c
@@ -479,15 +479,13 @@ static void test_LoadLibraryEx_search_flags(void)
{ { 6, 5 }, 5, 0 },
{ { 1, 1, 2 }, 0, 2 },
};
- char *p, path[MAX_PATH], buf[MAX_PATH];
+ char *p, path[MAX_PATH], buf[MAX_PATH], curdir[MAX_PATH];
WCHAR bufW[MAX_PATH];
DLL_DIRECTORY_COOKIE cookies[4];
unsigned int i, j, k;
BOOL ret;
HMODULE mod;
- if (!pAddDllDirectory || !pSetDllDirectoryA) return;
-
GetTempPathA( sizeof(path), path );
GetTempFileNameA( path, "tmp", 0, buf );
DeleteFileA( buf );
@@ -503,6 +501,80 @@ static void test_LoadLibraryEx_search_flags(void)
sprintf( p, "\\%u\\winetestdll.dll", i );
create_test_dll( buf );
}
+
+ GetCurrentDirectoryA( MAX_PATH, curdir );
+ *p = 0;
+ SetCurrentDirectoryA( buf );
+
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryA( "1\\winetestdll.dll" );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+
+ SetLastError( 0xdeadbeef );
+ sprintf( path, "%c:1\\winetestdll.dll", buf[0] );
+ mod = LoadLibraryA( path );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+
+ if (pAddDllDirectory)
+ {
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryExA( "1\\winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
+ ok( !mod, "LoadLibrary succeeded\n" );
+ ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
+
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryExA( path, 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+ }
+
+ strcpy( p, "\\1" );
+ SetCurrentDirectoryA( buf );
+
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryA( "winetestdll.dll" );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+
+ SetLastError( 0xdeadbeef );
+ sprintf( path, "%c:winetestdll.dll", buf[0] );
+ mod = LoadLibraryA( path );
+ ok( mod != NULL || broken(!mod), /* win10 disallows this but allows c:1\\winetestdll.dll */
+ "LoadLibrary failed err %u\n", GetLastError() );
+ if (!mod) ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
+ else FreeLibrary( mod );
+
+ SetLastError( 0xdeadbeef );
+ sprintf( path, "%s\\winetestdll.dll", buf + 2 );
+ mod = LoadLibraryA( path );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+
+ if (pAddDllDirectory)
+ {
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
+ ok( !mod, "LoadLibrary succeeded\n" );
+ ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
+
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryExA( path, 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+
+ SetLastError( 0xdeadbeef );
+ sprintf( path, "%s\\winetestdll.dll", buf + 2 );
+ mod = LoadLibraryExA( path, 0, LOAD_LIBRARY_SEARCH_SYSTEM32 );
+ ok( mod != NULL, "LoadLibrary failed err %u\n", GetLastError() );
+ FreeLibrary( mod );
+ }
+
+ SetCurrentDirectoryA( curdir );
+
+ if (!pAddDllDirectory || !pSetDllDirectoryA) goto done;
+
SetLastError( 0xdeadbeef );
mod = LoadLibraryExA( "winetestdll.dll", 0, LOAD_LIBRARY_SEARCH_APPLICATION_DIR );
ok( !mod, "LoadLibrary succeeded\n" );
@@ -539,6 +611,11 @@ static void test_LoadLibraryEx_search_flags(void)
ok( !mod, "LoadLibrary succeeded\n" );
ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
+ SetLastError( 0xdeadbeef );
+ mod = LoadLibraryA( "1\\winetestdll.dll" );
+ ok( !mod, "LoadLibrary succeeded\n" );
+ ok( GetLastError() == ERROR_MOD_NOT_FOUND, "wrong error %u\n", GetLastError() );
+
for (j = 0; j < ARRAY_SIZE(tests); j++)
{
for (k = 0; tests[j].add_dirs[k]; k++)
@@ -575,6 +652,7 @@ static void test_LoadLibraryEx_search_flags(void)
for (k = 0; tests[j].add_dirs[k]; k++) pRemoveDllDirectory( cookies[k] );
}
+done:
for (i = 1; i <= 6; i++)
{
sprintf( p, "\\%u\\winetestdll.dll", i );
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index a47dfe0..1f92eb0 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -2442,23 +2442,17 @@ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname,
return STATUS_NO_MEMORY;
}
*handle = open_dll_file( &nt_name, pwm, st );
- goto found;
}
-
- /* not found */
-
- if (!contains_path( libname ))
+ else /* not found, return the name as is, to be loaded as builtin */
{
- /* if libname doesn't contain a path at all, we simply return the name as is,
- * to be loaded as builtin */
len = strlenW(libname) * sizeof(WCHAR);
if (len >= *size) goto overflow;
strcpyW( filename, libname );
- goto found;
}
+ goto found;
}
- /* absolute path name, or relative path name but not found above */
+ /* absolute path name */
if (!RtlDosPathNameToNtPathName_U( libname, &nt_name, &file_part, NULL ))
{
More information about the wine-cvs
mailing list