[ros-diffs] [tkreuzer] 54054: [RTL] - Fix possible integer overflow in RtlpInitializeHeapSegment - Simplify loop in RtlIsDosDeviceName_Ustr - Make MonthLengths an array of UCHARs instead of ints - Remove point...

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Sat Oct 8 13:50:14 UTC 2011


Author: tkreuzer
Date: Sat Oct  8 13:50:14 2011
New Revision: 54054

URL: http://svn.reactos.org/svn/reactos?rev=54054&view=rev
Log:
[RTL]
- Fix possible integer overflow in RtlpInitializeHeapSegment
- Simplify loop in RtlIsDosDeviceName_Ustr
- Make MonthLengths an array of UCHARs instead of ints
- Remove pointless loops in RtlTimeToTimeFields
- Fix MSVC warnings

Modified:
    trunk/reactos/lib/rtl/actctx.c
    trunk/reactos/lib/rtl/heap.c
    trunk/reactos/lib/rtl/path.c
    trunk/reactos/lib/rtl/registry.c
    trunk/reactos/lib/rtl/time.c
    trunk/reactos/lib/rtl/unicode.c

Modified: trunk/reactos/lib/rtl/actctx.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/actctx.c?rev=54054&r1=54053&r2=54054&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/actctx.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/actctx.c [iso-8859-1] Sat Oct  8 13:50:14 2011
@@ -1794,7 +1794,7 @@
     status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileStandardInformation);
 
     if (status == STATUS_SUCCESS)
-        status = parse_manifest(acl, ai, filename, directory, shared, base, info.EndOfFile.QuadPart);
+        status = parse_manifest(acl, ai, filename, directory, shared, base, (SIZE_T)info.EndOfFile.QuadPart);
 
     NtUnmapViewOfSection( NtCurrentProcess(), base );
     NtClose( mapping );

Modified: trunk/reactos/lib/rtl/heap.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heap.c?rev=54054&r1=54053&r2=54054&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/heap.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/heap.c [iso-8859-1] Sat Oct  8 13:50:14 2011
@@ -913,9 +913,9 @@
 
     /* Initialise the Heap Entries contained within the Heap Segment */
     Segment->FirstEntry = &Segment->Entry + Segment->Entry.Size;
-    Segment->LastValidEntry = (PHEAP_ENTRY) ((ULONG_PTR) (Segment) + SegmentReserve);
-
-    if ((Segment->Entry.Size << HEAP_ENTRY_SHIFT) < SegmentCommit)
+    Segment->LastValidEntry = (PHEAP_ENTRY)((ULONG_PTR)Segment + SegmentReserve);
+
+    if (((SIZE_T)Segment->Entry.Size << HEAP_ENTRY_SHIFT) < SegmentCommit)
     {
         HeapEntry = Segment->FirstEntry;
 

Modified: trunk/reactos/lib/rtl/path.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/path.c?rev=54054&r1=54053&r2=54054&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/path.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/path.c [iso-8859-1] Sat Oct  8 13:50:14 2011
@@ -47,7 +47,7 @@
 {
     UNICODE_STRING PathCopy;
     PWCHAR Start, End;
-    ULONG PathChars, ColonCount = 0;
+    USHORT PathChars, ColonCount = 0;
     USHORT ReturnOffset = 0, ReturnLength;
     WCHAR c;
 
@@ -94,19 +94,18 @@
     }
 
     /* Check for extension or space, and truncate */
-    c = PathCopy.Buffer[PathChars - 1];
     do
     {
         /* Stop if we hit something else than a space or period */
+        c = PathCopy.Buffer[PathChars - 1];
         if ((c != '.') && (c != ' ')) break;
 
-        /* Fixup the lengths and get the next character */
+        /* Fixup the lengths */
         PathCopy.Length -= sizeof(WCHAR);
-        if (--PathChars) c = PathCopy.Buffer[PathChars - 1];
 
         /* Remember this for later */
         ColonCount++;
-    } while (PathChars);
+    } while (--PathChars);
 
     /* Anything still left? */
     if (PathChars)

Modified: trunk/reactos/lib/rtl/registry.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/registry.c?rev=54054&r1=54053&r2=54054&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/registry.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/registry.c [iso-8859-1] Sat Oct  8 13:50:14 2011
@@ -118,7 +118,7 @@
 {
     ULONG InfoLength;
     SIZE_T Length, SpareLength, c;
-    LONG RequiredLength;
+    ULONG RequiredLength;
     PCHAR SpareData, DataEnd;
     ULONG Type;
     PWCHAR Name, p, ValueEnd;
@@ -341,7 +341,7 @@
                 Status = RtlExpandEnvironmentStrings_U(Environment,
                                                        &Source,
                                                        &Destination,
-                                                       (PULONG)&RequiredLength);
+                                                       &RequiredLength);
                 Type = REG_SZ;
 
                 /* Check for success */

Modified: trunk/reactos/lib/rtl/time.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/time.c?rev=54054&r1=54053&r2=54054&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/time.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/time.c [iso-8859-1] Sat Oct  8 13:50:14 2011
@@ -38,14 +38,14 @@
 
 
 static const int YearLengths[2] =
-   {
-      DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
-   };
-static const int MonthLengths[2][MONSPERYEAR] =
-   {
-      { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
-      { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
-   };
+{
+    DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
+};
+static const UCHAR MonthLengths[2][MONSPERYEAR] =
+{
+    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
 
 static __inline int IsLeapYear(int Year)
 {
@@ -76,7 +76,7 @@
   TIME_FIELDS CurrentTimeFields;
   TIME_FIELDS CutoverSystemTimeFields;
   LARGE_INTEGER CutoverSystemTime;
-  CSHORT MonthLength;
+  UCHAR MonthLength;
   CSHORT Days;
   BOOLEAN NextYearsCutover = FALSE;
 
@@ -255,31 +255,19 @@
    IN PLARGE_INTEGER Time,
    OUT PTIME_FIELDS TimeFields)
 {
-   const int *Months;
-   int SecondsInDay, CurYear;
-   int LeapYear, CurMonth;
-   long int Days;
-   LONGLONG IntTime = (LONGLONG)Time->QuadPart;
+   const UCHAR *Months;
+   ULONG SecondsInDay, CurYear;
+   ULONG LeapYear, CurMonth;
+   ULONG Days;
+   ULONGLONG IntTime = Time->QuadPart;
 
    /* Extract millisecond from time and convert time into seconds */
    TimeFields->Milliseconds = (CSHORT) ((IntTime % TICKSPERSEC) / TICKSPERMSEC);
    IntTime = IntTime / TICKSPERSEC;
 
    /* Split the time into days and seconds within the day */
-   Days = IntTime / SECSPERDAY;
+   Days = (ULONG)(IntTime / SECSPERDAY);
    SecondsInDay = IntTime % SECSPERDAY;
-
-   /* Adjust the values for days and seconds in day */
-   while (SecondsInDay < 0)
-   {
-      SecondsInDay += SECSPERDAY;
-      Days--;
-   }
-   while (SecondsInDay >= SECSPERDAY)
-   {
-      SecondsInDay -= SECSPERDAY;
-      Days++;
-   }
 
    /* compute time of day */
    TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
@@ -297,20 +285,20 @@
    while (1)
    {
       LeapYear = IsLeapYear(CurYear);
-      if (Days < (long) YearLengths[LeapYear])
+      if (Days < YearLengths[LeapYear])
       {
          break;
       }
       CurYear++;
-      Days = Days - (long) YearLengths[LeapYear];
+      Days = Days - YearLengths[LeapYear];
    }
    TimeFields->Year = (CSHORT) CurYear;
 
    /* Compute month of year */
    LeapYear = IsLeapYear(CurYear);
    Months = MonthLengths[LeapYear];
-   for (CurMonth = 0; Days >= (long) Months[CurMonth]; CurMonth++)
-      Days = Days - (long) Months[CurMonth];
+   for (CurMonth = 0; Days >= Months[CurMonth]; CurMonth++)
+      Days = Days - Months[CurMonth];
    TimeFields->Month = (CSHORT) (CurMonth + 1);
    TimeFields->Day = (CSHORT) (Days + 1);
 }

Modified: trunk/reactos/lib/rtl/unicode.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/unicode.c?rev=54054&r1=54053&r2=54054&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/unicode.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/unicode.c [iso-8859-1] Sat Oct  8 13:50:14 2011
@@ -2495,8 +2495,7 @@
     IN PCUNICODE_STRING MatchString,
     OUT PUSHORT Position)
 {
-    SHORT i;
-    USHORT j;
+    USHORT i, j;
 
     switch (Flags)
     {
@@ -2520,7 +2519,7 @@
 
         case 1:
         {
-            for (i = SearchString->Length / sizeof(WCHAR) - 1; i >= 0; i--)
+            for (i = SearchString->Length / sizeof(WCHAR) - 1; (i + 1) > 0; i--)
             {
                 for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++)
                 {
@@ -2561,7 +2560,7 @@
 
         case 3:
         {
-            for (i = SearchString->Length / sizeof(WCHAR) - 1; i >= 0; i--)
+            for (i = SearchString->Length / sizeof(WCHAR) - 1; (i + 1) > 0; i--)
             {
                 j = 0;
 




More information about the Ros-diffs mailing list