Alexandre Julliard : ntdll: Fixed handling of fake dlls when loading a builtin. Reported by Jacek Caban.

Alexandre Julliard julliard at winehq.org
Wed Mar 5 06:24:24 CST 2008


Module: wine
Branch: master
Commit: 96fc6e317eef050ded00b22ec0191a8ff2def2ef
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=96fc6e317eef050ded00b22ec0191a8ff2def2ef

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Mar  5 12:21:19 2008 +0100

ntdll: Fixed handling of fake dlls when loading a builtin. Reported by Jacek Caban.

---

 dlls/ntdll/loader.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 11447eb..811540b 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1244,11 +1244,18 @@ NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE module, const ANSI_STRING *name,
  *
  * Check if a loaded native dll is a Wine fake dll.
  */
-static BOOL is_fake_dll( const void *base )
+static BOOL is_fake_dll( HANDLE handle )
 {
     static const char fakedll_signature[] = "Wine placeholder DLL";
-    const IMAGE_DOS_HEADER *dos = base;
+    char buffer[sizeof(IMAGE_DOS_HEADER) + sizeof(fakedll_signature)];
+    const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)buffer;
+    IO_STATUS_BLOCK io;
+    LARGE_INTEGER offset;
 
+    offset.QuadPart = 0;
+    if (NtReadFile( handle, 0, NULL, 0, &io, buffer, sizeof(buffer), &offset, NULL )) return FALSE;
+    if (io.Information < sizeof(buffer)) return FALSE;
+    if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
     if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
         !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return TRUE;
     return FALSE;
@@ -1427,13 +1434,6 @@ static NTSTATUS load_native_dll( LPCWSTR load_path, LPCWSTR name, HANDLE file,
     NtClose( mapping );
     if (status != STATUS_SUCCESS) return status;
 
-    if (is_fake_dll( module ))
-    {
-        TRACE( "%s is a fake dll, not loading it\n", debugstr_w(name) );
-        NtUnmapViewOfSection( NtCurrentProcess(), module );
-        return STATUS_DLL_NOT_FOUND;
-    }
-
     /* create the MODREF */
 
     if (!(wm = alloc_module( module, name ))) return STATUS_NO_MEMORY;
@@ -1870,6 +1870,13 @@ static NTSTATUS load_dll( LPCWSTR load_path, LPCWSTR libname, DWORD flags, WINE_
     main_exe = get_modref( NtCurrentTeb()->Peb->ImageBaseAddress );
     loadorder = get_load_order( main_exe ? main_exe->ldr.BaseDllName.Buffer : NULL, filename );
 
+    if (handle && is_fake_dll( handle ))
+    {
+        TRACE( "%s is a fake Wine dll\n", debugstr_w(filename) );
+        NtClose( handle );
+        handle = 0;
+    }
+
     switch(loadorder)
     {
     case LO_INVALID:




More information about the wine-cvs mailing list