Alexandre Julliard : ntdll: Align string data in RtlCreateProcessParametersEx().

Alexandre Julliard julliard at winehq.org
Tue Oct 16 15:53:07 CDT 2018


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Oct 16 20:45:10 2018 +0200

ntdll: Align string data in RtlCreateProcessParametersEx().

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

---

 dlls/ntdll/env.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c
index 417efb6..1d34e62 100644
--- a/dlls/ntdll/env.c
+++ b/dlls/ntdll/env.c
@@ -421,15 +421,21 @@ PRTL_USER_PROCESS_PARAMETERS WINAPI RtlDeNormalizeProcessParams( RTL_USER_PROCES
 }
 
 
+#define ROUND_SIZE(size) (((size) + sizeof(void *) - 1) & ~(sizeof(void *) - 1))
+
 /* append a unicode string to the process params data; helper for RtlCreateProcessParameters */
 static void append_unicode_string( void **data, const UNICODE_STRING *src,
                                    UNICODE_STRING *dst )
 {
     dst->Length = src->Length;
     dst->MaximumLength = src->MaximumLength;
-    dst->Buffer = *data;
-    memcpy( dst->Buffer, src->Buffer, dst->MaximumLength );
-    *data = (char *)dst->Buffer + dst->MaximumLength;
+    if (dst->MaximumLength)
+    {
+        dst->Buffer = *data;
+        memcpy( dst->Buffer, src->Buffer, dst->Length );
+        *data = (char *)dst->Buffer + ROUND_SIZE( dst->MaximumLength );
+    }
+    else dst->Buffer = NULL;
 }
 
 
@@ -482,17 +488,17 @@ NTSTATUS WINAPI RtlCreateProcessParametersEx( RTL_USER_PROCESS_PARAMETERS **resu
     env = Environment;
     while (*env) env += strlenW(env) + 1;
     env++;
-    env_size = (env - Environment) * sizeof(WCHAR);
+    env_size = ROUND_SIZE( (env - Environment) * sizeof(WCHAR) );
 
     size = (sizeof(RTL_USER_PROCESS_PARAMETERS)
-            + ImagePathName->MaximumLength
-            + DllPath->MaximumLength
-            + CurrentDirectoryName->MaximumLength
-            + CommandLine->MaximumLength
-            + WindowTitle->MaximumLength
-            + Desktop->MaximumLength
-            + ShellInfo->MaximumLength
-            + RuntimeInfo->MaximumLength);
+            + ROUND_SIZE( ImagePathName->MaximumLength )
+            + ROUND_SIZE( DllPath->MaximumLength )
+            + ROUND_SIZE( curdir.MaximumLength )
+            + ROUND_SIZE( CommandLine->MaximumLength )
+            + ROUND_SIZE( WindowTitle->MaximumLength )
+            + ROUND_SIZE( Desktop->MaximumLength )
+            + ROUND_SIZE( ShellInfo->MaximumLength )
+            + ROUND_SIZE( RuntimeInfo->MaximumLength ));
 
     total_size = size + env_size;
     ptr = NULL;




More information about the wine-cvs mailing list