- 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

svn path=/trunk/; revision=54054
This commit is contained in:
Timo Kreuzer 2011-10-08 13:50:14 +00:00
parent 56e0a450bd
commit 0fa1475dfd
6 changed files with 31 additions and 45 deletions

View file

@ -1794,7 +1794,7 @@ static NTSTATUS get_manifest_in_manifest_file( struct actctx_loader* acl, struct
status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileStandardInformation); status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileStandardInformation);
if (status == STATUS_SUCCESS) 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 ); NtUnmapViewOfSection( NtCurrentProcess(), base );
NtClose( mapping ); NtClose( mapping );

View file

@ -913,9 +913,9 @@ RtlpInitializeHeapSegment(IN OUT PHEAP Heap,
/* Initialise the Heap Entries contained within the Heap Segment */ /* Initialise the Heap Entries contained within the Heap Segment */
Segment->FirstEntry = &Segment->Entry + Segment->Entry.Size; Segment->FirstEntry = &Segment->Entry + Segment->Entry.Size;
Segment->LastValidEntry = (PHEAP_ENTRY) ((ULONG_PTR) (Segment) + SegmentReserve); Segment->LastValidEntry = (PHEAP_ENTRY)((ULONG_PTR)Segment + SegmentReserve);
if ((Segment->Entry.Size << HEAP_ENTRY_SHIFT) < SegmentCommit) if (((SIZE_T)Segment->Entry.Size << HEAP_ENTRY_SHIFT) < SegmentCommit)
{ {
HeapEntry = Segment->FirstEntry; HeapEntry = Segment->FirstEntry;

View file

@ -47,7 +47,7 @@ RtlIsDosDeviceName_Ustr(IN PUNICODE_STRING PathString)
{ {
UNICODE_STRING PathCopy; UNICODE_STRING PathCopy;
PWCHAR Start, End; PWCHAR Start, End;
ULONG PathChars, ColonCount = 0; USHORT PathChars, ColonCount = 0;
USHORT ReturnOffset = 0, ReturnLength; USHORT ReturnOffset = 0, ReturnLength;
WCHAR c; WCHAR c;
@ -94,19 +94,18 @@ RtlIsDosDeviceName_Ustr(IN PUNICODE_STRING PathString)
} }
/* Check for extension or space, and truncate */ /* Check for extension or space, and truncate */
c = PathCopy.Buffer[PathChars - 1];
do do
{ {
/* Stop if we hit something else than a space or period */ /* Stop if we hit something else than a space or period */
c = PathCopy.Buffer[PathChars - 1];
if ((c != '.') && (c != ' ')) break; if ((c != '.') && (c != ' ')) break;
/* Fixup the lengths and get the next character */ /* Fixup the lengths */
PathCopy.Length -= sizeof(WCHAR); PathCopy.Length -= sizeof(WCHAR);
if (--PathChars) c = PathCopy.Buffer[PathChars - 1];
/* Remember this for later */ /* Remember this for later */
ColonCount++; ColonCount++;
} while (PathChars); } while (--PathChars);
/* Anything still left? */ /* Anything still left? */
if (PathChars) if (PathChars)

View file

@ -118,7 +118,7 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
{ {
ULONG InfoLength; ULONG InfoLength;
SIZE_T Length, SpareLength, c; SIZE_T Length, SpareLength, c;
LONG RequiredLength; ULONG RequiredLength;
PCHAR SpareData, DataEnd; PCHAR SpareData, DataEnd;
ULONG Type; ULONG Type;
PWCHAR Name, p, ValueEnd; PWCHAR Name, p, ValueEnd;
@ -341,7 +341,7 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
Status = RtlExpandEnvironmentStrings_U(Environment, Status = RtlExpandEnvironmentStrings_U(Environment,
&Source, &Source,
&Destination, &Destination,
(PULONG)&RequiredLength); &RequiredLength);
Type = REG_SZ; Type = REG_SZ;
/* Check for success */ /* Check for success */

View file

@ -38,14 +38,14 @@
static const int YearLengths[2] = static const int YearLengths[2] =
{ {
DAYSPERNORMALYEAR, DAYSPERLEAPYEAR DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
}; };
static const int MonthLengths[2][MONSPERYEAR] = static const UCHAR MonthLengths[2][MONSPERYEAR] =
{ {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 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) static __inline int IsLeapYear(int Year)
{ {
@ -76,7 +76,7 @@ RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
TIME_FIELDS CurrentTimeFields; TIME_FIELDS CurrentTimeFields;
TIME_FIELDS CutoverSystemTimeFields; TIME_FIELDS CutoverSystemTimeFields;
LARGE_INTEGER CutoverSystemTime; LARGE_INTEGER CutoverSystemTime;
CSHORT MonthLength; UCHAR MonthLength;
CSHORT Days; CSHORT Days;
BOOLEAN NextYearsCutover = FALSE; BOOLEAN NextYearsCutover = FALSE;
@ -255,32 +255,20 @@ RtlTimeToTimeFields(
IN PLARGE_INTEGER Time, IN PLARGE_INTEGER Time,
OUT PTIME_FIELDS TimeFields) OUT PTIME_FIELDS TimeFields)
{ {
const int *Months; const UCHAR *Months;
int SecondsInDay, CurYear; ULONG SecondsInDay, CurYear;
int LeapYear, CurMonth; ULONG LeapYear, CurMonth;
long int Days; ULONG Days;
LONGLONG IntTime = (LONGLONG)Time->QuadPart; ULONGLONG IntTime = Time->QuadPart;
/* Extract millisecond from time and convert time into seconds */ /* Extract millisecond from time and convert time into seconds */
TimeFields->Milliseconds = (CSHORT) ((IntTime % TICKSPERSEC) / TICKSPERMSEC); TimeFields->Milliseconds = (CSHORT) ((IntTime % TICKSPERSEC) / TICKSPERMSEC);
IntTime = IntTime / TICKSPERSEC; IntTime = IntTime / TICKSPERSEC;
/* Split the time into days and seconds within the day */ /* Split the time into days and seconds within the day */
Days = IntTime / SECSPERDAY; Days = (ULONG)(IntTime / SECSPERDAY);
SecondsInDay = 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 */ /* compute time of day */
TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR); TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
SecondsInDay = SecondsInDay % SECSPERHOUR; SecondsInDay = SecondsInDay % SECSPERHOUR;
@ -297,20 +285,20 @@ RtlTimeToTimeFields(
while (1) while (1)
{ {
LeapYear = IsLeapYear(CurYear); LeapYear = IsLeapYear(CurYear);
if (Days < (long) YearLengths[LeapYear]) if (Days < YearLengths[LeapYear])
{ {
break; break;
} }
CurYear++; CurYear++;
Days = Days - (long) YearLengths[LeapYear]; Days = Days - YearLengths[LeapYear];
} }
TimeFields->Year = (CSHORT) CurYear; TimeFields->Year = (CSHORT) CurYear;
/* Compute month of year */ /* Compute month of year */
LeapYear = IsLeapYear(CurYear); LeapYear = IsLeapYear(CurYear);
Months = MonthLengths[LeapYear]; Months = MonthLengths[LeapYear];
for (CurMonth = 0; Days >= (long) Months[CurMonth]; CurMonth++) for (CurMonth = 0; Days >= Months[CurMonth]; CurMonth++)
Days = Days - (long) Months[CurMonth]; Days = Days - Months[CurMonth];
TimeFields->Month = (CSHORT) (CurMonth + 1); TimeFields->Month = (CSHORT) (CurMonth + 1);
TimeFields->Day = (CSHORT) (Days + 1); TimeFields->Day = (CSHORT) (Days + 1);
} }

View file

@ -2495,8 +2495,7 @@ RtlFindCharInUnicodeString(
IN PCUNICODE_STRING MatchString, IN PCUNICODE_STRING MatchString,
OUT PUSHORT Position) OUT PUSHORT Position)
{ {
SHORT i; USHORT i, j;
USHORT j;
switch (Flags) switch (Flags)
{ {
@ -2520,7 +2519,7 @@ RtlFindCharInUnicodeString(
case 1: 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++) for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++)
{ {
@ -2561,7 +2560,7 @@ RtlFindCharInUnicodeString(
case 3: 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; j = 0;