[PATCH] ntdll: Handle partial image load config structs

Martin Storsjo martin at martin.st
Wed Jul 22 15:01:35 CDT 2015


Some DLLs have a struct that only is large enough to contain the fields
that are relevant. Don't require the full struct to be available;
only make sure that it is large enough to contain the SecurityCookie
field. (This field is a DWORD in the 32 bit version, and a ULONGLONG
in the 64 bit version.)

This fixes loading ucrtbase.dll (from the redistributable visual
studio 2015 c++ runtime), which requires the security cookie to be
initialized. The 32 bit version of this DLL had loadcfg_size == 64,
where offsetof(IMAGE_LOAD_CONFIG_DIRECTORY, SecurityCookie) == 60.
That is, SecurityCookie is the last field included in the struct in
that case.

This fixes loading ucrtbase.dll.
---
 dlls/ntdll/virtual.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index ff947da..597b9c8 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1320,7 +1320,8 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
 
     loadcfg = RtlImageDirectoryEntryToData( (HMODULE)ptr, TRUE,
                                             IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &loadcfg_size );
-    if (loadcfg && loadcfg_size >= sizeof(*loadcfg))
+    if (loadcfg &&
+        loadcfg_size >= offsetof(IMAGE_LOAD_CONFIG_DIRECTORY, SecurityCookie) + sizeof(ULONG_PTR))
         set_security_cookie((ULONG_PTR *)loadcfg->SecurityCookie);
 
     /* set the image protections */
-- 
1.8.1.2




More information about the wine-patches mailing list