[ros-diffs] [ion] 54279: [KERNEL32]: In failure cases we should return one more byte for ANSI_NULL as well. Also fix another length check.

ion at svn.reactos.org ion at svn.reactos.org
Sun Oct 30 21:41:13 UTC 2011


Author: ion
Date: Sun Oct 30 21:41:12 2011
New Revision: 54279

URL: http://svn.reactos.org/svn/reactos?rev=54279&view=rev
Log:
[KERNEL32]: In failure cases we should return one more byte for ANSI_NULL as well. Also fix another length check.

Modified:
    trunk/reactos/dll/win32/kernel32/client/environ.c

Modified: trunk/reactos/dll/win32/kernel32/client/environ.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/environ.c?rev=54279&r1=54278&r2=54279&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/environ.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/environ.c [iso-8859-1] Sun Oct 30 21:41:12 2011
@@ -457,8 +457,8 @@
             Status = RtlExpandEnvironmentStrings_U(NULL, &SourceU, &DestU, &Length);
             if (NT_SUCCESS(Status))
             {
-                /* Get the ASCII length of the variable */
-                Result = RtlUnicodeStringToAnsiSize(&DestU);
+                /* Get the ASCII length of the variable, add a byte for NULL */
+                Result = RtlUnicodeStringToAnsiSize(&DestU) + sizeof(ANSI_NULL);
             }
         }
         else
@@ -475,16 +475,14 @@
 
         /* Check the size */
         Result = RtlUnicodeStringToAnsiSize(&DestU);
-        if (Result <= nSize)
+        if (Result <= UniSize)
         {
             /* Convert the string */
             RtlInitEmptyAnsiString(&Dest, lpDst, UniSize);
             Status = RtlUnicodeStringToAnsiString(&Dest, &DestU, FALSE);
-            if (!NT_SUCCESS(Status))
-            {
-                /* Clear the destination */
-                *lpDst = ANSI_NULL;
-            }
+            
+            /* Write a NULL-char in case of failure only */
+            if (!NT_SUCCESS(Status)) *lpDst = ANSI_NULL;
         }
     }
 Quickie:




More information about the Ros-diffs mailing list