[PATCH v5 2/2] ntdll: fix LdrGetDllPath with LOAD_WITH_ALTERED_SEARCH_PATH

Nick Fox nick at foxsec.net
Thu Oct 28 22:17:03 CDT 2021


Windows adds the executable directory to the path when LdrGetDllPath
is called with LOAD_WITH_ALTERED_SEARCH_PATH and a relative module name,
but only when the module name does not include directories.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=26350
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51821
Signed-off-by: Nick Fox <nick at foxsec.net>
---
v5: use helper function to duplicate less code per julliard's feedback
---
 dlls/kernel32/tests/path.c | 2 --
 dlls/ntdll/loader.c        | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index 2737910931c..0a0353d9f6d 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -2663,7 +2663,6 @@ static void test_LdrGetDllPath(void)
     ok( !ret, "LdrGetDllPath failed %x\n", ret );
     ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
     build_search_path( module_path, buffer, ARRAY_SIZE(buffer), NULL, TRUE, LOAD_WITH_ALTERED_SEARCH_PATH );
-    todo_wine
     ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
     pRtlReleasePath( path );

@@ -2675,7 +2674,6 @@ static void test_LdrGetDllPath(void)
     ok( !ret, "LdrGetDllPath failed %x\n", ret );
     ok( !unknown_ptr, "unknown ptr %p\n", unknown_ptr );
     build_search_path( module_path, buffer, ARRAY_SIZE(buffer), NULL, TRUE, LOAD_WITH_ALTERED_SEARCH_PATH );
-    todo_wine
     ok( path_equal( path, buffer ), "got %s expected %s\n", wine_dbgstr_w(path), wine_dbgstr_w(buffer));
     pRtlReleasePath( path );

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index dd41d6b66d2..28f59d59e0d 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -4211,7 +4211,7 @@ NTSTATUS WINAPI LdrGetDllPath( PCWSTR module, ULONG flags, PWSTR *path, PWSTR *u
     else
     {
         const WCHAR *dlldir = dll_directory.Length ? dll_directory.Buffer : NULL;
-        if (!(flags & LOAD_WITH_ALTERED_SEARCH_PATH))
+        if (!(flags & LOAD_WITH_ALTERED_SEARCH_PATH) || !wcschr( module, L'\\' ))
             module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
         status = get_dll_load_path( module, dlldir, dll_safe_mode, path );
     }
--
2.33.1





More information about the wine-devel mailing list