[PATCH] ntdll: Handle partial image load config structs (try 3)

Martin Storsjo martin at martin.st
Thu Jul 23 02:36:06 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 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.
---
Try 3: Changed sizeof(ULONG_PTR) to sizeof(loadcfg->SecurityCookie)
(Try 2 wasn't properly amended as intended; try 3 is what try 2
was supposed to be.)
---
 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..479ca79 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(loadcfg->SecurityCookie))
         set_security_cookie((ULONG_PTR *)loadcfg->SecurityCookie);
 
     /* set the image protections */
-- 
1.8.1.2




More information about the wine-patches mailing list