[ntdll] Care about empty fields of assembly_identity structure in actctx.c

Roman Mindalev lists at r000n.net
Wed Mar 11 12:08:36 CDT 2009


On parsing of manifest in PE module is possible access to zero address
and crash. It's happens because not all manifest attributes can be
specified and pointers in assembly_identity structure can be
uninitialized. This patch adds function for setting empty strings in
structure elements when they not initialized.
---
 dlls/ntdll/actctx.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/dlls/ntdll/actctx.c b/dlls/ntdll/actctx.c
index 79d475f..7ce5bad 100644
--- a/dlls/ntdll/actctx.c
+++ b/dlls/ntdll/actctx.c
@@ -332,12 +332,51 @@ static struct dll_redirect* add_dll_redirect(struct assembly* assembly)
     return &assembly->dlls[assembly->num_dlls++];
 }
 
+static void initialize_assembly_identity(struct assembly_identity *ai)
+{
+  ai->name = NULL;
+  ai->arch = NULL;
+  ai->public_key = NULL;
+  ai->language = NULL;
+  ai->type = NULL;
+}
+
+static void malloc_emptystrs_assembly_identity(struct assembly_identity *ai)
+{
+  if (ai->name == NULL)
+  {
+    ai->name = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(WCHAR) );
+    ai->name[0] = 0;
+  }
+  if (ai->arch == NULL)
+  {
+    ai->arch = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(WCHAR) );
+    ai->arch[0] = 0;
+  }
+  if (ai->public_key == NULL)
+  {
+    ai->public_key = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(WCHAR) );
+    ai->public_key[0] = 0;
+  }
+  if (ai->language == NULL)
+  {
+    ai->language = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(WCHAR) );
+    ai->language[0] = 0;
+  }
+  if (ai->type == NULL)
+  {
+    ai->type = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(WCHAR) );
+    ai->type[0] = 0;
+  }
+}
+
 static void free_assembly_identity(struct assembly_identity *ai)
 {
     RtlFreeHeap( GetProcessHeap(), 0, ai->name );
     RtlFreeHeap( GetProcessHeap(), 0, ai->arch );
     RtlFreeHeap( GetProcessHeap(), 0, ai->public_key );
     RtlFreeHeap( GetProcessHeap(), 0, ai->language );
+    RtlFreeHeap( GetProcessHeap(), 0, ai->type );
 }
 
 static struct entity* add_entity(struct entity_array *array, DWORD kind)
@@ -1168,6 +1207,8 @@ static BOOL parse_dependent_assembly_elem(xmlbuf_t* xmlbuf, struct actctx_loader
     xmlstr_t                    elem;
     BOOL                        end = FALSE, ret = TRUE;
 
+    initialize_assembly_identity(&ai);
+
     if (!parse_expect_no_attr(xmlbuf, &end) || end) return end;
 
     memset(&ai, 0, sizeof(ai));
@@ -1945,6 +1986,7 @@ static NTSTATUS lookup_assembly(struct actctx_loader* acl,
     UNICODE_STRING nameW;
     HANDLE file;
 
+    malloc_emptystrs_assembly_identity(ai);
     TRACE( "looking for name=%s version=%s arch=%s\n",
            debugstr_w(ai->name), debugstr_version(&ai->version), debugstr_w(ai->arch) );
 
-- 
1.6.2


--------------070401040203030407070605--



More information about the wine-patches mailing list