Alexandre Julliard : ntdll: Skip dlls of the wrong machine type when searching through the load path.

Alexandre Julliard julliard at winehq.org
Mon Feb 11 16:12:11 CST 2019


Module: wine
Branch: master
Commit: 9839bb7691a1b1c57a4ca501d03825420c1609d7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9839bb7691a1b1c57a4ca501d03825420c1609d7

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Sat Feb  9 21:21:47 2019 +0100

ntdll: Skip dlls of the wrong machine type when searching through the load path.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/tests/loader.c |  2 +-
 dlls/ntdll/loader.c          | 30 +++++++++++++++++++-----------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 165c05e..7046afc 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -685,7 +685,7 @@ static NTSTATUS map_image_section( const IMAGE_NT_HEADERS *nt_header, const IMAG
         /* some dlls with invalid entry point will crash, but this means we loaded the test dll */
         ok( !expect_fallback, "%u: got test dll but expected fallback\n", line );
     }
-    else todo_wine_if( !expect_status )
+    else
     {
         ok( ldr_status == expect_status ||
             broken(il_only && !expect_status && ldr_status == STATUS_INVALID_IMAGE_FORMAT),
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index dd6f437..56a6c2d 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1999,12 +1999,6 @@ static NTSTATUS load_native_dll( LPCWSTR load_path, const UNICODE_STRING *nt_nam
 
     TRACE("Trying native dll %s\n", debugstr_us(nt_name));
 
-    if (!is_valid_binary( module, image_info ))
-    {
-        NtUnmapViewOfSection( NtCurrentProcess(), module );
-        return STATUS_INVALID_IMAGE_FORMAT;
-    }
-
     /* perform base relocation, if necessary */
 
     if ((status = perform_relocations( module, nt, image_info->map_size )))
@@ -2363,6 +2357,12 @@ static NTSTATUS open_dll_file( const WCHAR *name, UNICODE_STRING *nt_name, WINE_
         if (status == STATUS_IMAGE_NOT_AT_BASE) status = STATUS_SUCCESS;
         NtClose( mapping );
     }
+    if (!status && !is_valid_binary( *module, image_info ))
+    {
+        TRACE( "%s is for arch %x, continuing search\n", debugstr_us(nt_name), image_info->machine );
+        NtUnmapViewOfSection( NtCurrentProcess(), *module );
+        status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
+    }
     return status;
 }
 
@@ -2377,6 +2377,7 @@ static NTSTATUS search_dll_file( LPCWSTR paths, LPCWSTR search, UNICODE_STRING *
                                  struct stat *st )
 {
     WCHAR *name;
+    BOOL found_image = FALSE;
     NTSTATUS status = STATUS_DLL_NOT_FOUND;
     ULONG len = strlenW( paths );
 
@@ -2397,15 +2398,20 @@ static NTSTATUS search_dll_file( LPCWSTR paths, LPCWSTR search, UNICODE_STRING *
         if (len && name[len - 1] != '\\') name[len++] = '\\';
         strcpyW( name + len, search );
         status = open_dll_file( name, nt_name, pwm, module, image_info, st );
-        if (status != STATUS_DLL_NOT_FOUND) goto done;
+        if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) found_image = TRUE;
+        else if (status != STATUS_DLL_NOT_FOUND) goto done;
         RtlFreeUnicodeString( nt_name );
         paths = ptr;
     }
 
-    /* not found, return file in the system dir to be loaded as builtin */
-    strcpyW( name, system_dir );
-    strcatW( name, search );
-    if (!RtlDosPathNameToNtPathName_U( name, nt_name, NULL, NULL )) status = STATUS_NO_MEMORY;
+    if (!found_image)
+    {
+        /* not found, return file in the system dir to be loaded as builtin */
+        strcpyW( name, system_dir );
+        strcatW( name, search );
+        if (!RtlDosPathNameToNtPathName_U( name, nt_name, NULL, NULL )) status = STATUS_NO_MEMORY;
+    }
+    else status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
 
 done:
     RtlFreeHeap( GetProcessHeap(), 0, name );
@@ -2463,6 +2469,8 @@ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname,
     else
         status = open_dll_file( libname, nt_name, pwm, module, image_info, st );
 
+    if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) status = STATUS_INVALID_IMAGE_FORMAT;
+
 done:
     RtlFreeHeap( GetProcessHeap(), 0, dllname );
     return status;




More information about the wine-cvs mailing list