From 415aa5eb4937510798fddde607fe1d51630dd754 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Sat, 4 Aug 2007 08:49:47 +0000 Subject: [PATCH] - Fix NtSetInformationThread(ThreadBasePriority) - Fix buffer overflow in KeRosDumpStackFrames - Fix usage of garbage/uninitialized handle entry local variable in ObpCreateHandle - Fix buffer overflow and logic bug in IoConnectInterrupt - Fix MSVC warnings svn path=/trunk/; revision=28153 --- reactos/include/ndk/ntndk.h | 1 - reactos/ntoskrnl/cc/fs.c | 2 +- reactos/ntoskrnl/config/cmname.c | 2 +- reactos/ntoskrnl/config/cmsysini.c | 2 +- reactos/ntoskrnl/ex/fmutex.c | 2 +- reactos/ntoskrnl/ex/init.c | 2 +- reactos/ntoskrnl/ex/sysinfo.c | 10 ++++---- reactos/ntoskrnl/inbv/inbv.c | 2 +- reactos/ntoskrnl/io/iomgr/controller.c | 2 +- reactos/ntoskrnl/io/iomgr/device.c | 6 ++--- reactos/ntoskrnl/io/iomgr/deviface.c | 8 +++---- reactos/ntoskrnl/io/iomgr/drvrlist.c | 4 ++-- reactos/ntoskrnl/io/iomgr/error.c | 9 ++++---- reactos/ntoskrnl/io/iomgr/file.c | 18 ++++++++------- reactos/ntoskrnl/io/iomgr/iorsrce.c | 4 ++-- reactos/ntoskrnl/io/iomgr/irq.c | 32 +++++++++++++------------- reactos/ntoskrnl/io/pnpmgr/pnpnotify.c | 4 ++-- reactos/ntoskrnl/io/pnpmgr/pnpreport.c | 4 ++-- reactos/ntoskrnl/io/pnpmgr/pnproot.c | 2 +- reactos/ntoskrnl/ke/bug.c | 2 +- reactos/ntoskrnl/ke/i386/ctxswitch.S | 2 +- reactos/ntoskrnl/ke/i386/exp.c | 3 ++- reactos/ntoskrnl/ke/i386/kiinit.c | 9 ++++---- reactos/ntoskrnl/ke/procobj.c | 6 ++--- reactos/ntoskrnl/ke/queue.c | 2 +- reactos/ntoskrnl/lpc/complete.c | 4 ++-- reactos/ntoskrnl/lpc/connect.c | 4 ++-- reactos/ntoskrnl/lpc/reply.c | 15 ++++++------ reactos/ntoskrnl/lpc/send.c | 12 +++++----- reactos/ntoskrnl/mm/procsup.c | 4 ++-- reactos/ntoskrnl/ob/obhandle.c | 10 ++++---- reactos/ntoskrnl/ps/psmgr.c | 2 +- reactos/ntoskrnl/ps/query.c | 2 +- reactos/ntoskrnl/ps/thread.c | 4 ++-- 34 files changed, 101 insertions(+), 96 deletions(-) diff --git a/reactos/include/ndk/ntndk.h b/reactos/include/ndk/ntndk.h index 0547f9f944b..b8f2770f3df 100644 --- a/reactos/include/ndk/ntndk.h +++ b/reactos/include/ndk/ntndk.h @@ -38,7 +38,6 @@ Author: #include // C Standard Header #include // C Standard Header #include // General Definitions -#include // Use Inlined Intrinsics // // Type Headers diff --git a/reactos/ntoskrnl/cc/fs.c b/reactos/ntoskrnl/cc/fs.c index be97a98b313..3e9bcd794ce 100644 --- a/reactos/ntoskrnl/cc/fs.c +++ b/reactos/ntoskrnl/cc/fs.c @@ -239,6 +239,6 @@ CcUninitializeCacheMap ( UNIMPLEMENTED; return FALSE; #else - return CcRosReleaseFileCache(FileObject); + return NT_SUCCESS(CcRosReleaseFileCache(FileObject)); #endif } diff --git a/reactos/ntoskrnl/config/cmname.c b/reactos/ntoskrnl/config/cmname.c index 4b8e2024a30..6151eadf485 100644 --- a/reactos/ntoskrnl/config/cmname.c +++ b/reactos/ntoskrnl/config/cmname.c @@ -102,7 +102,7 @@ CmpCompressedNameSize(IN PWCHAR Name, * that it will remain that way forever, so -never- assume this code * below internally! */ - return Length * sizeof(WCHAR); + return (USHORT)Length * sizeof(WCHAR); } LONG diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index 95bd50b6192..eb45f77cd55 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -455,7 +455,7 @@ CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock) } /* Setup the unicode string */ - RtlInitEmptyUnicodeString(&CmpLoadOptions, Buffer, Length); + RtlInitEmptyUnicodeString(&CmpLoadOptions, Buffer, (USHORT)Length); /* Add the load options and null-terminate */ RtlAnsiStringToUnicodeString(&CmpLoadOptions, &LoadString, FALSE); diff --git a/reactos/ntoskrnl/ex/fmutex.c b/reactos/ntoskrnl/ex/fmutex.c index b4d774fb2e7..7eb44e5d6e6 100644 --- a/reactos/ntoskrnl/ex/fmutex.c +++ b/reactos/ntoskrnl/ex/fmutex.c @@ -135,7 +135,7 @@ ExReleaseFastMutex(IN OUT PFAST_MUTEX FastMutex) /* Erase the owner */ FastMutex->Owner = NULL; - OldIrql = FastMutex->OldIrql; + OldIrql = (KIRQL)FastMutex->OldIrql; /* Increase the count */ if (InterlockedIncrement(&FastMutex->Count) <= 0) diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 26147fd10ea..2a5584db8d8 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -1094,7 +1094,7 @@ ExpInitializeExecutive(IN ULONG Cpu, } /* Update length */ - CmCSDVersionString.MaximumLength = sizeof(Buffer) - Remaining; + CmCSDVersionString.MaximumLength = (USHORT)sizeof(Buffer) - Remaining; } /* Check if we have an RC number */ diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index 89fe22c86ce..cd609fef63c 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -65,7 +65,7 @@ ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList, ModuleInfo->ImageSize = LdrEntry->SizeOfImage; ModuleInfo->Flags = LdrEntry->Flags; ModuleInfo->LoadCount = LdrEntry->LoadCount; - ModuleInfo->LoadOrderIndex = ModuleCount; + ModuleInfo->LoadOrderIndex = (USHORT)ModuleCount; ModuleInfo->InitOrderIndex = 0; /* Setup name */ @@ -231,7 +231,7 @@ NtQuerySystemEnvironmentValue (IN PUNICODE_STRING VariableName, { ANSI_STRING AName; UNICODE_STRING WName; - BOOLEAN Result; + ARC_STATUS Result; PCH Value; ANSI_STRING AValue; UNICODE_STRING WValue; @@ -417,7 +417,7 @@ NtSetSystemEnvironmentValue (IN PUNICODE_STRING VariableName, TRUE); if(NT_SUCCESS(Status)) { - BOOLEAN Result = HalSetEnvironmentVariable(AName.Buffer, + ARC_STATUS Result = HalSetEnvironmentVariable(AName.Buffer, AValue.Buffer); Status = (Result ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL); @@ -766,7 +766,7 @@ QSI_DEF(SystemProcessInformation) SpiCur->UserTime.QuadPart = pr->Pcb.UserTime * 100000LL; SpiCur->KernelTime.QuadPart = pr->Pcb.KernelTime * 100000LL; SpiCur->ImageName.Length = strlen(pr->ImageFileName) * sizeof(WCHAR); - SpiCur->ImageName.MaximumLength = inLen; + SpiCur->ImageName.MaximumLength = (USHORT)inLen; SpiCur->ImageName.Buffer = (void*)(pCur+curSize); // copy name to the end of the struct @@ -1058,7 +1058,7 @@ QSI_DEF(SystemHandleInformation) for (Count = 0; HandleCount > 0 ; HandleCount--) { - Shi->Handles[i].UniqueProcessId = (ULONG)pr->UniqueProcessId; + Shi->Handles[i].UniqueProcessId = (USHORT)(ULONG)pr->UniqueProcessId; Count++; i++; } diff --git a/reactos/ntoskrnl/inbv/inbv.c b/reactos/ntoskrnl/inbv/inbv.c index adbb392e8b5..06bdf66b582 100644 --- a/reactos/ntoskrnl/inbv/inbv.c +++ b/reactos/ntoskrnl/inbv/inbv.c @@ -372,7 +372,7 @@ InbvSolidColorFill(IN ULONG Left, if (InbvBootDriverInstalled) { /* Call bootvid */ - VidSolidColorFill(Left, Top, Width, Height, Color); + VidSolidColorFill(Left, Top, Width, Height, (UCHAR)Color); } /* FIXME: Headless */ diff --git a/reactos/ntoskrnl/io/iomgr/controller.c b/reactos/ntoskrnl/io/iomgr/controller.c index 52922c6af52..a27f25ad979 100644 --- a/reactos/ntoskrnl/io/iomgr/controller.c +++ b/reactos/ntoskrnl/io/iomgr/controller.c @@ -92,7 +92,7 @@ IoCreateController(IN ULONG Size) /* Zero the Object and set its data */ RtlZeroMemory(Controller, sizeof(CONTROLLER_OBJECT) + Size); Controller->Type = IO_TYPE_CONTROLLER; - Controller->Size = sizeof(CONTROLLER_OBJECT) + Size; + Controller->Size = (CSHORT)sizeof(CONTROLLER_OBJECT) + Size; Controller->ControllerExtension = (Controller + 1); /* Initialize its Queue */ diff --git a/reactos/ntoskrnl/io/iomgr/device.c b/reactos/ntoskrnl/io/iomgr/device.c index 1086d330682..2a5012523ba 100644 --- a/reactos/ntoskrnl/io/iomgr/device.c +++ b/reactos/ntoskrnl/io/iomgr/device.c @@ -765,7 +765,7 @@ IoCreateDevice(IN PDRIVER_OBJECT DriverObject, * because that's only padding for the DevObjExt and not part of the Object. */ CreatedDeviceObject->Type = IO_TYPE_DEVICE; - CreatedDeviceObject->Size = sizeof(DEVICE_OBJECT) + DeviceExtensionSize; + CreatedDeviceObject->Size = (USHORT)sizeof(DEVICE_OBJECT) + DeviceExtensionSize; /* The kernel extension is after the driver internal extension */ DeviceObjectExtension = (PDEVOBJ_EXTENSION) @@ -1402,7 +1402,7 @@ IoStartNextPacketByKey(IN PDEVICE_OBJECT DeviceObject, IopStartNextPacketByKeyEx(DeviceObject, Key, DOE_SIO_WITH_KEY | - (Cancelable) ? DOE_SIO_CANCELABLE : 0); + (Cancelable ? DOE_SIO_CANCELABLE : 0)); } else { @@ -1431,7 +1431,7 @@ IoStartNextPacket(IN PDEVICE_OBJECT DeviceObject, IopStartNextPacketByKeyEx(DeviceObject, 0, DOE_SIO_NO_KEY | - (Cancelable) ? DOE_SIO_CANCELABLE : 0); + (Cancelable ? DOE_SIO_CANCELABLE : 0)); } else { diff --git a/reactos/ntoskrnl/io/iomgr/deviface.c b/reactos/ntoskrnl/io/iomgr/deviface.c index 31f4ba3b2a2..81122e429b2 100644 --- a/reactos/ntoskrnl/io/iomgr/deviface.c +++ b/reactos/ntoskrnl/io/iomgr/deviface.c @@ -300,7 +300,7 @@ IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, } /* Open device key */ - KeyName.Length = KeyName.MaximumLength = DeviceBi->NameLength; + KeyName.Length = KeyName.MaximumLength = (USHORT)DeviceBi->NameLength; KeyName.Buffer = DeviceBi->Name; InitializeObjectAttributes( &ObjectAttributes, @@ -370,7 +370,7 @@ IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, goto cleanup; } - KeyName.Length = KeyName.MaximumLength = ReferenceBi->NameLength; + KeyName.Length = KeyName.MaximumLength = (USHORT)ReferenceBi->NameLength; KeyName.Buffer = ReferenceBi->Name; if (RtlEqualUnicodeString(&KeyName, &Control, TRUE)) { @@ -475,7 +475,7 @@ IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, Status = STATUS_UNSUCCESSFUL; goto cleanup; } - KeyName.Length = KeyName.MaximumLength = bip->DataLength - 4 * sizeof(WCHAR); + KeyName.Length = KeyName.MaximumLength = (USHORT)bip->DataLength - 4 * sizeof(WCHAR); KeyName.Buffer = &((PWSTR)bip->Data)[4]; if (KeyName.Length && KeyName.Buffer[KeyName.Length / sizeof(WCHAR)] == UNICODE_NULL) { @@ -976,7 +976,7 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, return STATUS_INVALID_PARAMETER_1; } GuidString.Buffer = StartPosition; - GuidString.MaximumLength = GuidString.Length = (ULONG_PTR)(EndPosition + 1) - (ULONG_PTR)StartPosition; + GuidString.MaximumLength = GuidString.Length = (USHORT)((ULONG_PTR)(EndPosition + 1) - (ULONG_PTR)StartPosition); /* Get pointer to the PDO */ Status = IoGetDeviceObjectPointer( diff --git a/reactos/ntoskrnl/io/iomgr/drvrlist.c b/reactos/ntoskrnl/io/iomgr/drvrlist.c index 64edabc01d6..c47681a753b 100644 --- a/reactos/ntoskrnl/io/iomgr/drvrlist.c +++ b/reactos/ntoskrnl/io/iomgr/drvrlist.c @@ -323,8 +323,8 @@ IoCreateDriverList(VOID) if (KeyInfo->NameLength < MAX_PATH * sizeof(WCHAR)) { - SubKeyName.Length = KeyInfo->NameLength; - SubKeyName.MaximumLength = KeyInfo->NameLength + sizeof(WCHAR); + SubKeyName.Length = (USHORT)KeyInfo->NameLength; + SubKeyName.MaximumLength = (USHORT)KeyInfo->NameLength + sizeof(WCHAR); SubKeyName.Buffer = KeyInfo->Name; SubKeyName.Buffer[SubKeyName.Length / sizeof(WCHAR)] = 0; diff --git a/reactos/ntoskrnl/io/iomgr/error.c b/reactos/ntoskrnl/io/iomgr/error.c index 2de55c5bb68..a72db5fa8eb 100644 --- a/reactos/ntoskrnl/io/iomgr/error.c +++ b/reactos/ntoskrnl/io/iomgr/error.c @@ -338,8 +338,8 @@ IopLogWorker(IN PVOID Parameter) if (NT_SUCCESS(Status)) { /* Success, update the information */ - ObjectNameInfo->Name.Length = 100 - - DriverNameLength; + ObjectNameInfo->Name.Length = (USHORT)100 - + DriverNameLength; } } } @@ -434,7 +434,8 @@ IopLogWorker(IN PVOID Parameter) /* Update size */ InterlockedExchangeAdd(&IopTotalLogSize, - -(LogEntry->Size - sizeof(ERROR_LOG_ENTRY))); + -(LONG)(LogEntry->Size - + sizeof(ERROR_LOG_ENTRY))); } /* Free the LPC Message */ @@ -557,7 +558,7 @@ IoFreeErrorLogEntry(IN PVOID ElEntry) /* Decrease total allocation size and free the entry */ InterlockedExchangeAdd(&IopTotalLogSize, - -(LogEntry->Size - sizeof(ERROR_LOG_ENTRY))); + -(LONG)(LogEntry->Size - sizeof(ERROR_LOG_ENTRY))); ExFreePool(LogEntry); } diff --git a/reactos/ntoskrnl/io/iomgr/file.c b/reactos/ntoskrnl/io/iomgr/file.c index 68d4024d453..3950c044479 100644 --- a/reactos/ntoskrnl/io/iomgr/file.c +++ b/reactos/ntoskrnl/io/iomgr/file.c @@ -512,7 +512,7 @@ IopParseDevice(IN PVOID ParseObject, StackLoc->Parameters.Create.EaLength = OpenPacket->EaLength; /* Set the flags */ - StackLoc->Flags = OpenPacket->Options; + StackLoc->Flags = (UCHAR)OpenPacket->Options; StackLoc->Flags |= !(Attributes & OBJ_CASE_INSENSITIVE) ? SL_CASE_SENSITIVE: 0; break; @@ -764,7 +764,8 @@ IopParseDevice(IN PVOID ParseObject, FileObject->DeviceObject = NULL; /* Save this now because the FO might go away */ - OpenCancelled = FileObject->Flags & FO_FILE_OPEN_CANCELLED; + OpenCancelled = FileObject->Flags & FO_FILE_OPEN_CANCELLED ? + TRUE : FALSE; /* Clear the file object in the open packet */ OpenPacket->FileObject = NULL; @@ -1370,9 +1371,10 @@ IopQueryNameFile(IN PVOID ObjectBody, /* Setup the length and maximum length */ FileLength = (ULONG_PTR)p - (ULONG_PTR)ObjectNameInfo; - ObjectNameInfo->Name.Length = FileLength - sizeof(OBJECT_NAME_INFORMATION); - ObjectNameInfo->Name.MaximumLength = ObjectNameInfo->Name.Length + - sizeof(UNICODE_NULL); + ObjectNameInfo->Name.Length = (USHORT)FileLength - + sizeof(OBJECT_NAME_INFORMATION); + ObjectNameInfo->Name.MaximumLength = (USHORT)ObjectNameInfo->Name.Length + + sizeof(UNICODE_NULL); /* Free buffer and return */ ExFreePool(LocalInfo); @@ -1745,8 +1747,8 @@ IoCreateFile(OUT PHANDLE FileHandle, OpenPacket.OriginalAttributes = *ObjectAttributes; OpenPacket.AllocationSize = SafeAllocationSize; OpenPacket.CreateOptions = CreateOptions; - OpenPacket.FileAttributes = FileAttributes; - OpenPacket.ShareAccess = ShareAccess; + OpenPacket.FileAttributes = (USHORT)FileAttributes; + OpenPacket.ShareAccess = (USHORT)ShareAccess; OpenPacket.EaBuffer = SystemEaBuffer; OpenPacket.EaLength = EaLength; OpenPacket.Options = Options; @@ -2078,7 +2080,7 @@ STDCALL IoIsFileOriginRemote(IN PFILE_OBJECT FileObject) { /* Return the flag status */ - return (FileObject->Flags & FO_REMOTE_ORIGIN); + return FileObject->Flags & FO_REMOTE_ORIGIN ? TRUE : FALSE; } /* diff --git a/reactos/ntoskrnl/io/iomgr/iorsrce.c b/reactos/ntoskrnl/io/iomgr/iorsrce.c index e6e0dc0b6a0..c208166387f 100644 --- a/reactos/ntoskrnl/io/iomgr/iorsrce.c +++ b/reactos/ntoskrnl/io/iomgr/iorsrce.c @@ -533,8 +533,8 @@ IopQueryBusDescription( /* Enumerate the Bus. */ BusString.Buffer = BasicInformation->Name; - BusString.Length = BasicInformation->NameLength; - BusString.MaximumLength = BasicInformation->NameLength; + BusString.Length = (USHORT)BasicInformation->NameLength; + BusString.MaximumLength = (USHORT)BasicInformation->NameLength; /* Open a handle to the Root Registry Key */ InitializeObjectAttributes( diff --git a/reactos/ntoskrnl/io/iomgr/irq.c b/reactos/ntoskrnl/io/iomgr/irq.c index 07486e25ab2..aaf0880c788 100644 --- a/reactos/ntoskrnl/io/iomgr/irq.c +++ b/reactos/ntoskrnl/io/iomgr/irq.c @@ -36,28 +36,28 @@ IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, PIO_INTERRUPT IoInterrupt; PKSPIN_LOCK SpinLockUsed; BOOLEAN FirstRun = TRUE; - ULONG count; - LONG i; + CCHAR Count = 0; + KAFFINITY Affinity; PAGED_CODE(); /* Assume failure */ *InterruptObject = NULL; - /* Convert the Mask */ - ProcessorEnableMask &= ((1 << KeNumberProcessors) - 1); - - /* Make sure at least one CPU is on it */ - if (!ProcessorEnableMask) return STATUS_INVALID_PARAMETER; - - /* Determine the allocation */ - for (i = 0, count = 0; i < KeNumberProcessors; i++) + /* Get the affinity */ + Affinity = ProcessorEnableMask & KeActiveProcessors; + while (Affinity) { - if (ProcessorEnableMask & (1 << i)) count++; + /* Increase count */ + if (Affinity & 1) Count++; + Affinity >>= 1; } + /* Make sure we have a valid CPU count */ + if (!Count) return STATUS_INVALID_PARAMETER; + /* Allocate the array of I/O Interrupts */ IoInterrupt = ExAllocatePoolWithTag(NonPagedPool, - (count - 1)* sizeof(KINTERRUPT) + + (Count - 1) * sizeof(KINTERRUPT) + sizeof(IO_INTERRUPT), TAG_KINTERRUPT); if (!IoInterrupt) return STATUS_INSUFFICIENT_RESOURCES; @@ -74,10 +74,10 @@ IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, RtlZeroMemory(IoInterrupt, sizeof(IO_INTERRUPT)); /* Now create all the interrupts */ - for (i = 0; i < KeNumberProcessors; i++) + for (Count = 0; Affinity; Count++, Affinity >>= 1) { /* Check if it's enabled for this CPU */ - if (ProcessorEnableMask & (1 << i)) + if (Affinity & 1) { /* Check which one we will use */ InterruptUsed = FirstRun ? &IoInterrupt->FirstInterrupt : Interrupt; @@ -92,7 +92,7 @@ IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, SynchronizeIrql, InterruptMode, ShareVector, - i, + Count, FloatingSave); /* Connect it */ @@ -122,7 +122,7 @@ IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, else { /* Move on to the next one */ - IoInterrupt->Interrupt[i] = Interrupt++; + IoInterrupt->Interrupt[(UCHAR)Count] = Interrupt++; } } } diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c b/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c index d01d3e7e604..79e10df0394 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c @@ -10,9 +10,9 @@ /* INCLUDES ******************************************************************/ -#define NDEBUG #include -#include +#define NDEBUG +#include #if defined (ALLOC_PRAGMA) #pragma alloc_text(INIT, IopInitPnpNotificationImplementation) diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpreport.c b/reactos/ntoskrnl/io/pnpmgr/pnpreport.c index 3bd084c6e4e..b1ac6d1771f 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpreport.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpreport.c @@ -10,9 +10,9 @@ /* INCLUDES ******************************************************************/ -#define NDEBUG #include -#include +#define NDEBUG +#include /* FUNCTIONS *****************************************************************/ diff --git a/reactos/ntoskrnl/io/pnpmgr/pnproot.c b/reactos/ntoskrnl/io/pnpmgr/pnproot.c index b5106c9c89b..45759c2a84a 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnproot.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnproot.c @@ -287,7 +287,7 @@ QueryStringCallback( String->Buffer = ExAllocatePoolWithTag(PagedPool, ValueLength, TAG_PNP_ROOT); if (String->Buffer == NULL) return STATUS_NO_MEMORY; - String->Length = String->MaximumLength = ValueLength; + String->Length = String->MaximumLength = (USHORT)ValueLength; RtlCopyMemory(String->Buffer, ValueData, ValueLength); if (ValueLength > 0 && String->Buffer[ValueLength / sizeof(WCHAR) - 1] == L'\0') String->Length -= sizeof(WCHAR); diff --git a/reactos/ntoskrnl/ke/bug.c b/reactos/ntoskrnl/ke/bug.c index 5454c50c864..57e7f5d1698 100644 --- a/reactos/ntoskrnl/ke/bug.c +++ b/reactos/ntoskrnl/ke/bug.c @@ -143,7 +143,7 @@ KeRosDumpStackFrames(IN PULONG Frame OPTIONAL, PLDR_DATA_TABLE_ENTRY LdrEntry; /* If the caller didn't ask, assume 32 frames */ - if (!FrameCount) FrameCount = 32; + if (!FrameCount || FrameCount > 32) FrameCount = 32; /* Get the current frames */ FrameCount = RtlCaptureStackBackTrace(2, FrameCount, (PVOID*)Frames, NULL); diff --git a/reactos/ntoskrnl/ke/i386/ctxswitch.S b/reactos/ntoskrnl/ke/i386/ctxswitch.S index f46255b0cee..217410f061f 100644 --- a/reactos/ntoskrnl/ke/i386/ctxswitch.S +++ b/reactos/ntoskrnl/ke/i386/ctxswitch.S @@ -10,7 +10,7 @@ /* INCLUDES ******************************************************************/ -#include +//#include #include .intel_syntax noprefix diff --git a/reactos/ntoskrnl/ke/i386/exp.c b/reactos/ntoskrnl/ke/i386/exp.c index b014b5b4967..c9dd0fbd5bb 100644 --- a/reactos/ntoskrnl/ke/i386/exp.c +++ b/reactos/ntoskrnl/ke/i386/exp.c @@ -170,7 +170,8 @@ KiRecordDr7(OUT PULONG Dr7Ptr, if (Mask != NewMask) { /* Update it */ - KeGetCurrentThread()->DispatcherHeader.DebugActive = NewMask; + KeGetCurrentThread()->DispatcherHeader.DebugActive = + (BOOLEAN)NewMask; } } diff --git a/reactos/ntoskrnl/ke/i386/kiinit.c b/reactos/ntoskrnl/ke/i386/kiinit.c index ef1b1b409e7..2e6293f25de 100644 --- a/reactos/ntoskrnl/ke/i386/kiinit.c +++ b/reactos/ntoskrnl/ke/i386/kiinit.c @@ -216,10 +216,11 @@ KiInitMachineDependent(VOID) CurrentSample->TSCStart; /* Compute CPU Speed */ - CurrentSample->MHz = ((CurrentSample->TSCDelta * - CurrentSample->PerfFreq.QuadPart + - 500000) / - (CurrentSample->PerfDelta * 1000000)); + CurrentSample->MHz = (ULONG)((CurrentSample->TSCDelta * + CurrentSample-> + PerfFreq.QuadPart + 500000) / + (CurrentSample->PerfDelta * + 1000000)); /* Check if this isn't the first sample */ if (Sample) diff --git a/reactos/ntoskrnl/ke/procobj.c b/reactos/ntoskrnl/ke/procobj.c index cdf16015dbd..bf9f2717b5a 100644 --- a/reactos/ntoskrnl/ke/procobj.c +++ b/reactos/ntoskrnl/ke/procobj.c @@ -308,7 +308,7 @@ KeSetPriorityAndQuantumProcess(IN PKPROCESS Process, /* Save the current base priority and update it */ OldPriority = Process->BasePriority; - Process->BasePriority = Priority; + Process->BasePriority = (SCHAR)Priority; /* Calculate the priority delta */ Delta = Priority - OldPriority; @@ -364,7 +364,7 @@ KeSetPriorityAndQuantumProcess(IN PKPROCESS Process, } /* Update priority and quantum */ - Thread->BasePriority = NewPriority; + Thread->BasePriority = (SCHAR)NewPriority; Thread->Quantum = Thread->QuantumReset; /* Disable decrements and update priority */ @@ -426,7 +426,7 @@ KeSetPriorityAndQuantumProcess(IN PKPROCESS Process, } /* Update priority and quantum */ - Thread->BasePriority = NewPriority; + Thread->BasePriority = (SCHAR)NewPriority; Thread->Quantum = Thread->QuantumReset; /* Disable decrements and update priority */ diff --git a/reactos/ntoskrnl/ke/queue.c b/reactos/ntoskrnl/ke/queue.c index a2bddee7070..efe31c44064 100644 --- a/reactos/ntoskrnl/ke/queue.c +++ b/reactos/ntoskrnl/ke/queue.c @@ -358,7 +358,7 @@ KeRemoveQueue(IN PKQUEUE Queue, { /* Check if the timer expired */ InterruptTime.QuadPart = KeQueryInterruptTime(); - if (InterruptTime.QuadPart >= Timer->DueTime.QuadPart) + if ((ULONG64)InterruptTime.QuadPart >= Timer->DueTime.QuadPart) { /* It did, so we don't need to wait */ QueueEntry = (PLIST_ENTRY)STATUS_TIMEOUT; diff --git a/reactos/ntoskrnl/lpc/complete.c b/reactos/ntoskrnl/lpc/complete.c index 6acbd2f2540..67de3871976 100644 --- a/reactos/ntoskrnl/lpc/complete.c +++ b/reactos/ntoskrnl/lpc/complete.c @@ -134,8 +134,8 @@ NtAcceptConnectPort(OUT PHANDLE PortHandle, } /* Set the sizes of our reply message */ - Message->Request.u1.s1.DataLength = sizeof(LPCP_CONNECTION_MESSAGE) + - ConnectionInfoLength; + Message->Request.u1.s1.DataLength = (CSHORT)ConnectionInfoLength + + sizeof(LPCP_CONNECTION_MESSAGE); Message->Request.u1.s1.TotalLength = sizeof(LPCP_MESSAGE) + Message->Request.u1.s1.DataLength; diff --git a/reactos/ntoskrnl/lpc/connect.c b/reactos/ntoskrnl/lpc/connect.c index 84f1854efe0..1d71c382a05 100644 --- a/reactos/ntoskrnl/lpc/connect.c +++ b/reactos/ntoskrnl/lpc/connect.c @@ -352,8 +352,8 @@ NtSecureConnectPort(OUT PHANDLE PortHandle, ConnectMessage->SectionToMap = SectionToMap; /* Set the data for the connection request message */ - Message->Request.u1.s1.DataLength = sizeof(LPCP_CONNECTION_MESSAGE) + - ConnectionInfoLength; + Message->Request.u1.s1.DataLength = (CSHORT)ConnectionInfoLength + + sizeof(LPCP_CONNECTION_MESSAGE); Message->Request.u1.s1.TotalLength = sizeof(LPCP_MESSAGE) + Message->Request.u1.s1.DataLength; Message->Request.u2.s2.Type = LPC_CONNECTION_REQUEST; diff --git a/reactos/ntoskrnl/lpc/reply.c b/reactos/ntoskrnl/lpc/reply.c index 24fc263b64b..55fa1c0d7eb 100644 --- a/reactos/ntoskrnl/lpc/reply.c +++ b/reactos/ntoskrnl/lpc/reply.c @@ -180,8 +180,8 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle, if (ReplyMessage) { /* Validate its length */ - if ((ReplyMessage->u1.s1.DataLength + sizeof(PORT_MESSAGE)) > - ReplyMessage->u1.s1.TotalLength) + if (((ULONG)ReplyMessage->u1.s1.DataLength + sizeof(PORT_MESSAGE)) > + (ULONG)ReplyMessage->u1.s1.TotalLength) { /* Fail */ return STATUS_INVALID_PARAMETER; @@ -204,8 +204,9 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle, if (ReplyMessage) { /* Validate its length in respect to the port object */ - if ((ReplyMessage->u1.s1.TotalLength > Port->MaxMessageLength) || - (ReplyMessage->u1.s1.TotalLength <= ReplyMessage->u1.s1.DataLength)) + if (((ULONG)ReplyMessage->u1.s1.TotalLength > Port->MaxMessageLength) || + ((ULONG)ReplyMessage->u1.s1.TotalLength <= + (ULONG)ReplyMessage->u1.s1.DataLength)) { /* Too large, fail */ ObDereferenceObject(Port); @@ -408,9 +409,9 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle, Message = NULL; /* Setup the receive message */ - ReceiveMessage->u1.s1.TotalLength = sizeof(LPCP_MESSAGE) + - ConnectionInfoLength; - ReceiveMessage->u1.s1.DataLength = ConnectionInfoLength; + ReceiveMessage->u1.s1.TotalLength = (CSHORT)(sizeof(LPCP_MESSAGE) + + ConnectionInfoLength); + ReceiveMessage->u1.s1.DataLength = (CSHORT)ConnectionInfoLength; RtlCopyMemory(ReceiveMessage + 1, ConnectMessage + 1, ConnectionInfoLength); diff --git a/reactos/ntoskrnl/lpc/send.c b/reactos/ntoskrnl/lpc/send.c index 7c3cbd72d3f..b880506ac5d 100644 --- a/reactos/ntoskrnl/lpc/send.c +++ b/reactos/ntoskrnl/lpc/send.c @@ -60,8 +60,8 @@ LpcRequestPort(IN PVOID PortObject, if (LpcMessage->u2.s2.DataInfoOffset) return STATUS_INVALID_PARAMETER; /* Validate message sizes */ - if ((LpcMessage->u1.s1.TotalLength > Port->MaxMessageLength) || - (LpcMessage->u1.s1.TotalLength <= LpcMessage->u1.s1.DataLength)) + if (((ULONG)LpcMessage->u1.s1.TotalLength > Port->MaxMessageLength) || + ((ULONG)LpcMessage->u1.s1.TotalLength <= (ULONG)LpcMessage->u1.s1.DataLength)) { /* Fail */ return STATUS_PORT_MESSAGE_TOO_LONG; @@ -241,8 +241,8 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle, MessageType = LpcRequest->u2.s2.Type; /* Validate the length */ - if ((LpcRequest->u1.s1.DataLength + sizeof(PORT_MESSAGE)) > - LpcRequest->u1.s1.TotalLength) + if (((ULONG)LpcRequest->u1.s1.DataLength + sizeof(PORT_MESSAGE)) > + (ULONG)LpcRequest->u1.s1.TotalLength) { /* Fail */ return STATUS_INVALID_PARAMETER; @@ -258,8 +258,8 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle, if (!NT_SUCCESS(Status)) return Status; /* Validate the message length */ - if ((LpcRequest->u1.s1.TotalLength > Port->MaxMessageLength) || - (LpcRequest->u1.s1.TotalLength <= LpcRequest->u1.s1.DataLength)) + if (((ULONG)LpcRequest->u1.s1.TotalLength > Port->MaxMessageLength) || + ((ULONG)LpcRequest->u1.s1.TotalLength <= (ULONG)LpcRequest->u1.s1.DataLength)) { /* Fail */ ObDereferenceObject(Port); diff --git a/reactos/ntoskrnl/mm/procsup.c b/reactos/ntoskrnl/mm/procsup.c index 1346262f5de..6042a1d27cb 100644 --- a/reactos/ntoskrnl/mm/procsup.c +++ b/reactos/ntoskrnl/mm/procsup.c @@ -40,7 +40,7 @@ MmSetMemoryPriorityProcess(IN PEPROCESS Process, } /* Save the old priority and update it */ - OldPriority = Process->Vm.Flags.MemoryPriority; + OldPriority = (UCHAR)Process->Vm.Flags.MemoryPriority; Process->Vm.Flags.MemoryPriority = MemoryPriority; /* Return the old priority */ @@ -331,7 +331,7 @@ MmCreatePeb(PEPROCESS Process) Peb->OSMinorVersion = NtMinorVersion; Peb->OSBuildNumber = (USHORT)(NtBuildNumber & 0x3FFF); Peb->OSPlatformId = 2; /* VER_PLATFORM_WIN32_NT */ - Peb->OSCSDVersion = CmNtCSDVersion; + Peb->OSCSDVersion = (USHORT)CmNtCSDVersion; /* Heap and Debug Data */ Peb->NumberOfProcessors = KeNumberProcessors; diff --git a/reactos/ntoskrnl/ob/obhandle.c b/reactos/ntoskrnl/ob/obhandle.c index a2d771f06a0..2d0af033d74 100644 --- a/reactos/ntoskrnl/ob/obhandle.c +++ b/reactos/ntoskrnl/ob/obhandle.c @@ -1362,7 +1362,7 @@ ObpCreateUnnamedHandle(IN PVOID Object, { /* Dereference it as many times as required */ InterlockedExchangeAdd(&ObjectHeader->PointerCount, - -AdditionalReferences); + -(LONG)AdditionalReferences); } /* Decrement the handle count and detach */ @@ -1457,6 +1457,9 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason, return STATUS_OBJECT_TYPE_MISMATCH; } + /* Save the object header */ + NewEntry.Object = ObjectHeader; + /* Check if this is a kernel handle */ if (HandleAttributes & OBJ_KERNEL_HANDLE) { @@ -1530,9 +1533,6 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason, /* Now we can release the object */ if (Context) ObpCleanupDirectoryLookup(Context); - /* Save the object header */ - NewEntry.Object = ObjectHeader; - /* Save the access mask */ NewEntry.GrantedAccess = GrantedAccess; @@ -1617,7 +1617,7 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason, { /* Dereference it many times */ InterlockedExchangeAdd(&ObjectHeader->PointerCount, - -(AdditionalReferences - 1)); + -(LONG)(AdditionalReferences - 1)); } /* Dereference the object one last time */ diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index 50c8ac6ef81..f9347c93970 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -58,7 +58,7 @@ BOOLEAN PspDoingGiveBacks; /* PRIVATE FUNCTIONS *********************************************************/ -ULONG +USHORT NTAPI NameToOrdinal(IN PCHAR Name, IN PVOID DllBase, diff --git a/reactos/ntoskrnl/ps/query.c b/reactos/ntoskrnl/ps/query.c index 561b189c7b0..8a2550c1ba4 100644 --- a/reactos/ntoskrnl/ps/query.c +++ b/reactos/ntoskrnl/ps/query.c @@ -815,7 +815,7 @@ NtSetInformationThread(IN HANDLE ThreadHandle, (Priority < THREAD_BASE_PRIORITY_MIN)) { /* These ones are OK */ - if ((Priority != THREAD_BASE_PRIORITY_LOWRT + 1) || + if ((Priority != THREAD_BASE_PRIORITY_LOWRT + 1) && (Priority != THREAD_BASE_PRIORITY_IDLE - 1)) { /* Check if the process is real time */ diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 5c6012bb98b..ebf09667ccf 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -703,7 +703,7 @@ BOOLEAN NTAPI PsGetThreadHardErrorsAreDisabled(IN PETHREAD Thread) { - return Thread->HardErrorsAreDisabled; + return Thread->HardErrorsAreDisabled ? TRUE : FALSE; } /* @@ -823,7 +823,7 @@ BOOLEAN NTAPI PsIsThreadImpersonating(IN PETHREAD Thread) { - return Thread->ActiveImpersonationInfo; + return Thread->ActiveImpersonationInfo ? TRUE : FALSE; } /*