[ros-diffs] [fireball] 38809: - RtlOemStringToCountedUnicodeString improvements: * Fix STATUS_BUFFER_OVERFLOW when destination string's MaximumLength and Length are equal. * Add comments.

fireball at svn.reactos.org fireball at svn.reactos.org
Sat Jan 17 09:38:26 CET 2009


Author: fireball
Date: Sat Jan 17 02:38:25 2009
New Revision: 38809

URL: http://svn.reactos.org/svn/reactos?rev=38809&view=rev
Log:
- RtlOemStringToCountedUnicodeString improvements:
 * Fix STATUS_BUFFER_OVERFLOW when destination string's MaximumLength and Length are equal.
 * Add comments.

Modified:
    trunk/reactos/lib/rtl/unicode.c

Modified: trunk/reactos/lib/rtl/unicode.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/unicode.c?rev=38809&r1=38808&r2=38809&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/unicode.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/unicode.c [iso-8859-1] Sat Jan 17 02:38:25 2009
@@ -1182,29 +1182,35 @@
 
     PAGED_CODE_RTL();
 
+    /* Calculate size of the string */
     Length = RtlOemStringToCountedUnicodeSize(OemSource);
 
+    /* If it's 0 then zero out dest string and return */
     if (!Length)
     {
         RtlZeroMemory(UniDest, sizeof(UNICODE_STRING));
         return STATUS_SUCCESS;
     }
 
+    /* Check if length is a sane value */
     if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
 
+    /* Store it in dest string */
     UniDest->Length = (USHORT)Length;
 
+    /* If we're asked to alloc the string - do so */
     if (AllocateDestinationString)
     {
         UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
         UniDest->MaximumLength = Length;
         if (!UniDest->Buffer) return STATUS_NO_MEMORY;
     }
-    else if (UniDest->Length >= UniDest->MaximumLength)
+    else if (UniDest->Length > UniDest->MaximumLength)
     {
         return STATUS_BUFFER_OVERFLOW;
     }
 
+    /* Do the conversion */
     Status = RtlOemToUnicodeN(UniDest->Buffer,
                               UniDest->Length,
                               &Index,
@@ -1213,6 +1219,7 @@
 
     if (!NT_SUCCESS(Status) && AllocateDestinationString)
     {
+        /* Conversion failed, free dest string and return status code */
         RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
         UniDest->Buffer = NULL;
         return Status;



More information about the Ros-diffs mailing list