From 47fed8f5bc89344af054b70c2d3a7bea02b2113c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 24 Mar 2021 10:54:05 +0100 Subject: [PATCH] ntdll: Don't set the DllPath parameter by default. Recent Windows versions don't set it either. Signed-off-by: Alexandre Julliard --- dlls/kernelbase/process.c | 10 +++---- dlls/ntdll/env.c | 55 +++++++++++++++++++-------------------- dlls/ntdll/loader.c | 32 +++++++++++------------ dlls/ntdll/unix/env.c | 1 - 4 files changed, 45 insertions(+), 53 deletions(-) diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c index 44bf0606c7a..550ab34e720 100644 --- a/dlls/kernelbase/process.c +++ b/dlls/kernelbase/process.c @@ -144,9 +144,9 @@ static RTL_USER_PROCESS_PARAMETERS *create_process_params( const WCHAR *filename const STARTUPINFOW *startup ) { RTL_USER_PROCESS_PARAMETERS *params; - UNICODE_STRING imageW, dllpathW, curdirW, cmdlineW, titleW, desktopW, runtimeW, newdirW; + UNICODE_STRING imageW, curdirW, cmdlineW, titleW, desktopW, runtimeW, newdirW; WCHAR imagepath[MAX_PATH]; - WCHAR *load_path, *dummy, *envW = env; + WCHAR *envW = env; if (!GetLongPathNameW( filename, imagepath, MAX_PATH )) lstrcpynW( imagepath, filename, MAX_PATH ); if (!GetFullPathNameW( imagepath, MAX_PATH, imagepath, NULL )) lstrcpynW( imagepath, filename, MAX_PATH ); @@ -171,26 +171,22 @@ static RTL_USER_PROCESS_PARAMETERS *create_process_params( const WCHAR *filename else cur_dir = NULL; } - LdrGetDllPath( imagepath, LOAD_WITH_ALTERED_SEARCH_PATH, &load_path, &dummy ); RtlInitUnicodeString( &imageW, imagepath ); - RtlInitUnicodeString( &dllpathW, load_path ); RtlInitUnicodeString( &curdirW, cur_dir ); RtlInitUnicodeString( &cmdlineW, cmdline ); RtlInitUnicodeString( &titleW, startup->lpTitle ? startup->lpTitle : imagepath ); RtlInitUnicodeString( &desktopW, startup->lpDesktop ); runtimeW.Buffer = (WCHAR *)startup->lpReserved2; runtimeW.Length = runtimeW.MaximumLength = startup->cbReserved2; - if (RtlCreateProcessParametersEx( ¶ms, &imageW, &dllpathW, cur_dir ? &curdirW : NULL, + if (RtlCreateProcessParametersEx( ¶ms, &imageW, NULL, cur_dir ? &curdirW : NULL, &cmdlineW, envW, &titleW, &desktopW, NULL, &runtimeW, PROCESS_PARAMS_FLAG_NORMALIZED )) { RtlFreeUnicodeString( &newdirW ); - RtlReleasePath( load_path ); if (envW != env) RtlFreeHeap( GetProcessHeap(), 0, envW ); return NULL; } RtlFreeUnicodeString( &newdirW ); - RtlReleasePath( load_path ); if (flags & CREATE_NEW_PROCESS_GROUP) params->ConsoleFlags = 1; if (flags & CREATE_NEW_CONSOLE) params->ConsoleHandle = (HANDLE)1; /* KERNEL32_CONSOLE_ALLOC */ diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index f615945cd33..62f93603d55 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -542,7 +542,7 @@ NTSTATUS WINAPI RtlCreateProcessParametersEx( RTL_USER_PROCESS_PARAMETERS **resu RtlAcquirePebLock(); cur_params = NtCurrentTeb()->Peb->ProcessParameters; - if (!DllPath) DllPath = &cur_params->DllPath; + if (!DllPath) DllPath = &null_str; if (!CurrentDirectoryName) { if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */ @@ -637,46 +637,45 @@ void WINAPI RtlDestroyProcessParameters( RTL_USER_PROCESS_PARAMETERS *params ) */ void init_user_process_params(void) { - WCHAR *env, *load_path, *dummy; + WCHAR *env; SIZE_T env_size; RTL_USER_PROCESS_PARAMETERS *new_params, *params = NtCurrentTeb()->Peb->ProcessParameters; - UNICODE_STRING curdir, dllpath; + UNICODE_STRING curdir; /* environment needs to be a separate memory block */ env_size = params->EnvironmentSize; - env = params->Environment; if ((env = RtlAllocateHeap( GetProcessHeap(), 0, max( env_size, sizeof(WCHAR) )))) { if (env_size) memcpy( env, params->Environment, env_size ); else env[0] = 0; - params->Environment = env; } - if (!params->DllPath.MaximumLength) /* not inherited from parent process */ - { - LdrGetDllPath( params->ImagePathName.Buffer, 0, &load_path, &dummy ); - RtlInitUnicodeString( &dllpath, load_path ); + params->Environment = NULL; /* avoid copying it */ + if (RtlCreateProcessParametersEx( &new_params, ¶ms->ImagePathName, ¶ms->DllPath, + ¶ms->CurrentDirectory.DosPath, + ¶ms->CommandLine, NULL, ¶ms->WindowTitle, ¶ms->Desktop, + ¶ms->ShellInfo, ¶ms->RuntimeInfo, + PROCESS_PARAMS_FLAG_NORMALIZED )) + return; - env = params->Environment; - params->Environment = NULL; /* avoid copying it */ - if (RtlCreateProcessParametersEx( &new_params, ¶ms->ImagePathName, &dllpath, - ¶ms->CurrentDirectory.DosPath, - ¶ms->CommandLine, NULL, ¶ms->ImagePathName, NULL, NULL, NULL, - PROCESS_PARAMS_FLAG_NORMALIZED )) - return; + new_params->Environment = env; + new_params->DebugFlags = params->DebugFlags; + new_params->ConsoleHandle = params->ConsoleHandle; + new_params->ConsoleFlags = params->ConsoleFlags; + new_params->hStdInput = params->hStdInput; + new_params->hStdOutput = params->hStdOutput; + new_params->hStdError = params->hStdError; + new_params->dwX = params->dwX; + new_params->dwY = params->dwY; + new_params->dwXSize = params->dwXSize; + new_params->dwYSize = params->dwYSize; + new_params->dwXCountChars = params->dwXCountChars; + new_params->dwYCountChars = params->dwYCountChars; + new_params->dwFillAttribute = params->dwFillAttribute; + new_params->dwFlags = params->dwFlags; + new_params->wShowWindow = params->wShowWindow; - new_params->Environment = env; - new_params->hStdInput = params->hStdInput; - new_params->hStdOutput = params->hStdOutput; - new_params->hStdError = params->hStdError; - new_params->ConsoleHandle = params->ConsoleHandle; - new_params->dwXCountChars = params->dwXCountChars; - new_params->dwYCountChars = params->dwYCountChars; - new_params->wShowWindow = params->wShowWindow; - NtCurrentTeb()->Peb->ProcessParameters = params = new_params; - - RtlReleasePath( load_path ); - } + NtCurrentTeb()->Peb->ProcessParameters = params = new_params; if (RtlSetCurrentDirectory_U( ¶ms->CurrentDirectory.DosPath )) { diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index bf03c1f9baa..01644df7763 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -80,6 +80,7 @@ static ULONG path_safe_mode; /* path mode set by RtlSetSearchPathMode */ static ULONG dll_safe_mode = 1; /* dll search mode */ static UNICODE_STRING dll_directory; /* extra path for LdrSetDllDirectory */ static DWORD default_search_flags; /* default flags set by LdrSetDefaultDllDirectories */ +static WCHAR *default_load_path; /* default dll search path */ struct dll_dir_entry { @@ -1687,9 +1688,8 @@ NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE module, const ANSI_STRING *name, else if ((exports = RtlImageDirectoryEntryToData( module, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size ))) { - LPCWSTR load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; - void *proc = name ? find_named_export( module, exports, exp_size, name->Buffer, -1, load_path ) - : find_ordinal_export( module, exports, exp_size, ord - exports->Base, load_path ); + void *proc = name ? find_named_export( module, exports, exp_size, name->Buffer, -1, NULL ) + : find_ordinal_export( module, exports, exp_size, ord - exports->Base, NULL ); if (proc) { *address = proc; @@ -2423,6 +2423,10 @@ static void build_main_module(void) RTL_USER_PROCESS_PARAMETERS *params = NtCurrentTeb()->Peb->ProcessParameters; void *module = NtCurrentTeb()->Peb->ImageBaseAddress; + default_load_path = params->DllPath.Buffer; + if (!default_load_path) + get_dll_load_path( params->ImagePathName.Buffer, NULL, dll_safe_mode, &default_load_path ); + NtQueryInformationProcess( GetCurrentProcess(), ProcessImageInformation, &info, sizeof(info), NULL ); if (info.ImageCharacteristics & IMAGE_FILE_DLL) { @@ -2438,8 +2442,7 @@ static void build_main_module(void) #endif status = RtlDosPathNameToNtPathName_U_WithStatus( params->ImagePathName.Buffer, &nt_name, NULL, NULL ); if (status) goto failed; - status = build_module( params->DllPath.Buffer, &nt_name, &module, &info, - NULL, DONT_RESOLVE_DLL_REFERENCES, &wm ); + status = build_module( NULL, &nt_name, &module, &info, NULL, DONT_RESOLVE_DLL_REFERENCES, &wm ); RtlFreeUnicodeString( &nt_name ); if (!status) return; failed: @@ -2561,7 +2564,10 @@ static NTSTATUS search_dll_file( LPCWSTR paths, LPCWSTR search, UNICODE_STRING * WCHAR *name; BOOL found_image = FALSE; NTSTATUS status = STATUS_DLL_NOT_FOUND; - ULONG len = wcslen( paths ); + ULONG len; + + if (!paths) paths = default_load_path; + len = wcslen( paths ); if (len < wcslen( system_dir )) len = wcslen( system_dir ); len += wcslen( search ) + 2; @@ -2796,7 +2802,6 @@ NTSTATUS WINAPI DECLSPEC_HOTPATCH LdrLoadDll(LPCWSTR path_name, DWORD flags, RtlEnterCriticalSection( &loader_section ); - if (!path_name) path_name = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; nts = load_dll( path_name, libname->Buffer, L".dll", flags, &wm ); if (nts == STATUS_SUCCESS && !(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS)) @@ -2829,8 +2834,6 @@ NTSTATUS WINAPI LdrGetDllHandle( LPCWSTR load_path, ULONG flags, const UNICODE_S RtlEnterCriticalSection( &loader_section ); - if (!load_path) load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; - status = find_dll_file( load_path, name->Buffer, L".dll", &nt_name, &wm, &mapping, &image_info, &id ); if (wm) *base = wm->ldr.DllBase; @@ -3465,7 +3468,6 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR ULONG_PTR cookie; WINE_MODREF *wm; void **entry; - LPCWSTR load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; #ifdef __i386__ entry = (void **)&context->Eax; @@ -3488,9 +3490,9 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR { actctx_init(); if (wm->ldr.Flags & LDR_COR_ILONLY) - status = fixup_imports_ilonly( wm, load_path, entry ); + status = fixup_imports_ilonly( wm, NULL, entry ); else - status = fixup_imports( wm, load_path ); + status = fixup_imports( wm, NULL ); if (status) { @@ -3971,7 +3973,6 @@ static void map_wow64cpu(void) */ static NTSTATUS process_init(void) { - RTL_USER_PROCESS_PARAMETERS *params; WINE_MODREF *wm; NTSTATUS status; ANSI_STRING func_name; @@ -4006,8 +4007,6 @@ static NTSTATUS process_init(void) #endif init_user_process_params(); - params = peb->ProcessParameters; - load_global_options(); version_init(); build_main_module(); @@ -4032,8 +4031,7 @@ static NTSTATUS process_init(void) map_wow64cpu(); #endif - if ((status = load_dll( params->DllPath.Buffer, L"C:\\windows\\system32\\kernel32.dll", - NULL, 0, &wm )) != STATUS_SUCCESS) + if ((status = load_dll( NULL, L"C:\\windows\\system32\\kernel32.dll", NULL, 0, &wm )) != STATUS_SUCCESS) { MESSAGE( "wine: could not load kernel32.dll, status %x\n", status ); NtTerminateProcess( GetCurrentProcess(), status ); diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 38bd56241ad..e4932473fcc 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -1767,7 +1767,6 @@ static void run_wineboot( WCHAR *env, SIZE_T size ) params.Environment = env; params.EnvironmentSize = size; init_unicode_string( ¶ms.CurrentDirectory.DosPath, system_dir + 4 ); - init_unicode_string( ¶ms.DllPath, system_dir + 4 ); init_unicode_string( ¶ms.ImagePathName, appnameW + 4 ); init_unicode_string( ¶ms.CommandLine, cmdlineW ); init_unicode_string( ¶ms.WindowTitle, appnameW + 4 );