diff --git a/reactos/ntoskrnl/cc/view.c b/reactos/ntoskrnl/cc/view.c index a19171c9a39..1be81e0383a 100644 --- a/reactos/ntoskrnl/cc/view.c +++ b/reactos/ntoskrnl/cc/view.c @@ -1325,6 +1325,10 @@ CcInitView(VOID) } Buffer = ExAllocatePool(NonPagedPool, CI_CACHESEG_MAPPING_REGION_SIZE / (PAGE_SIZE * 8)); + if (!Buffer) + { + KeBugCheck(CACHE_MANAGER); + } RtlInitializeBitMap(&CiCacheSegMappingRegionAllocMap, Buffer, CI_CACHESEG_MAPPING_REGION_SIZE / PAGE_SIZE); RtlClearAllBits(&CiCacheSegMappingRegionAllocMap); diff --git a/reactos/ntoskrnl/fstub/disksup.c b/reactos/ntoskrnl/fstub/disksup.c index 3d87077d12d..d217122309f 100644 --- a/reactos/ntoskrnl/fstub/disksup.c +++ b/reactos/ntoskrnl/fstub/disksup.c @@ -452,6 +452,8 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock, PartialInformation = (PKEY_VALUE_PARTIAL_INFORMATION)ExAllocatePool(PagedPool, sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(REG_DISK_MOUNT_INFO)); + if (!Buffer1 || !Buffer2 || !PartialInformation) return; + DiskMountInfo = (PREG_DISK_MOUNT_INFO) PartialInformation->Data; /* Open or Create the 'MountedDevices' key */ @@ -526,6 +528,14 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock, goto end_assign_disks; LayoutArray = ExAllocatePool(NonPagedPool, ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION)); + if (!LayoutArray) + { + ExFreePool(PartialInformation); + ExFreePool(Buffer2); + ExFreePool(Buffer1); + if (hKey) ZwClose(hKey); + } + RtlZeroMemory(LayoutArray, ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION)); for (i = 0; i < ConfigInfo->DiskCount; i++) diff --git a/reactos/ntoskrnl/io/iomgr/driver.c b/reactos/ntoskrnl/io/iomgr/driver.c index 7d605d64ead..1264454e04b 100644 --- a/reactos/ntoskrnl/io/iomgr/driver.c +++ b/reactos/ntoskrnl/io/iomgr/driver.c @@ -1007,6 +1007,7 @@ IopUnloadDriver(PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers) ObjectName.Length = (wcslen(Start) + 8) * sizeof(WCHAR); ObjectName.MaximumLength = ObjectName.Length + sizeof(WCHAR); ObjectName.Buffer = ExAllocatePool(PagedPool, ObjectName.MaximumLength); + if (!ObjectName.Buffer) return STATUS_INSUFFICIENT_RESOURCES; wcscpy(ObjectName.Buffer, L"\\Driver\\"); memcpy(ObjectName.Buffer + 8, Start, ObjectName.Length - 8 * sizeof(WCHAR)); ObjectName.Buffer[ObjectName.Length/sizeof(WCHAR)] = 0; diff --git a/reactos/ntoskrnl/io/iomgr/file.c b/reactos/ntoskrnl/io/iomgr/file.c index d007ace307e..9d2cbc461ca 100644 --- a/reactos/ntoskrnl/io/iomgr/file.c +++ b/reactos/ntoskrnl/io/iomgr/file.c @@ -2872,7 +2872,7 @@ NtCancelIoFile(IN HANDLE FileHandle, } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - + /* Ignore exception */ } _SEH2_END; diff --git a/reactos/ntoskrnl/io/iomgr/iofunc.c b/reactos/ntoskrnl/io/iomgr/iofunc.c index 08b600f1151..4c454de3963 100644 --- a/reactos/ntoskrnl/io/iomgr/iofunc.c +++ b/reactos/ntoskrnl/io/iomgr/iofunc.c @@ -1015,6 +1015,12 @@ NtFlushBuffersFile(IN HANDLE FileHandle, { /* Use local event */ Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO); + if (!Event) + { + /* We failed */ + ObDereferenceObject(FileObject); + return STATUS_INSUFFICIENT_RESOURCES; + } KeInitializeEvent(Event, SynchronizationEvent, FALSE); LocalEvent = TRUE; } @@ -1548,6 +1554,7 @@ NtQueryDirectoryFile(IN HANDLE FileHandle, { /* Allocate an MDL */ Mdl = IoAllocateMdl(FileInformation, Length, FALSE, TRUE, Irp); + if (!Mdl) ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES); MmProbeAndLockPages(Mdl, PreviousMode, IoWriteAccess); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) @@ -1636,6 +1643,7 @@ NtQueryInformationFile(IN HANDLE FileHandle, PVOID NormalContext; KIRQL OldIrql; IO_STATUS_BLOCK KernelIosb; + PAGED_CODE(); IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle); /* Check if we're called from user mode */ @@ -1749,6 +1757,11 @@ NtQueryInformationFile(IN HANDLE FileHandle, { /* Use local event */ Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO); + if (!Event) + { + ObDereferenceObject(FileObject); + return STATUS_INSUFFICIENT_RESOURCES; + } KeInitializeEvent(Event, SynchronizationEvent, FALSE); LocalEvent = TRUE; } @@ -2666,6 +2679,11 @@ NtUnlockFile(IN HANDLE FileHandle, { /* Use local event */ Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO); + if (!Event) + { + ObDereferenceObject(FileObject); + return STATUS_INSUFFICIENT_RESOURCES; + } KeInitializeEvent(Event, SynchronizationEvent, FALSE); LocalEvent = TRUE; } @@ -3102,6 +3120,11 @@ NtQueryVolumeInformationFile(IN HANDLE FileHandle, { /* Use local event */ Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO); + if (!Event) + { + ObDereferenceObject(FileObject); + return STATUS_INSUFFICIENT_RESOURCES; + } KeInitializeEvent(Event, SynchronizationEvent, FALSE); LocalEvent = TRUE; } @@ -3263,6 +3286,11 @@ NtSetVolumeInformationFile(IN HANDLE FileHandle, { /* Use local event */ Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), TAG_IO); + if (!Event) + { + ObDereferenceObject(FileObject); + return STATUS_INSUFFICIENT_RESOURCES; + } KeInitializeEvent(Event, SynchronizationEvent, FALSE); LocalEvent = TRUE; } diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c b/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c index 91ffd138204..c328c80965f 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c @@ -61,6 +61,11 @@ IopNotifyPlugPlayNotification( PagedPool, sizeof(DEVICE_INTERFACE_CHANGE_NOTIFICATION), TAG_PNP_NOTIFY); + if (!NotificationInfos) + { + KeReleaseGuardedMutex(&PnpNotifyListLock); + return; + } NotificationInfos->Version = 1; NotificationInfos->Size = sizeof(DEVICE_INTERFACE_CHANGE_NOTIFICATION); RtlCopyMemory(&NotificationInfos->Event, Event, sizeof(GUID)); @@ -75,6 +80,11 @@ IopNotifyPlugPlayNotification( PagedPool, sizeof(HWPROFILE_CHANGE_NOTIFICATION), TAG_PNP_NOTIFY); + if (!NotificationInfos) + { + KeReleaseGuardedMutex(&PnpNotifyListLock); + return; + } NotificationInfos->Version = 1; NotificationInfos->Size = sizeof(HWPROFILE_CHANGE_NOTIFICATION); RtlCopyMemory(&NotificationInfos->Event, Event, sizeof(GUID)); @@ -87,6 +97,11 @@ IopNotifyPlugPlayNotification( PagedPool, sizeof(TARGET_DEVICE_REMOVAL_NOTIFICATION), TAG_PNP_NOTIFY); + if (!NotificationInfos) + { + KeReleaseGuardedMutex(&PnpNotifyListLock); + return; + } NotificationInfos->Version = 1; NotificationInfos->Size = sizeof(TARGET_DEVICE_REMOVAL_NOTIFICATION); RtlCopyMemory(&NotificationInfos->Event, Event, sizeof(GUID)); diff --git a/reactos/ntoskrnl/ke/profobj.c b/reactos/ntoskrnl/ke/profobj.c index 21dda7b6cfc..a4b68e5a052 100644 --- a/reactos/ntoskrnl/ke/profobj.c +++ b/reactos/ntoskrnl/ke/profobj.c @@ -62,6 +62,7 @@ KeStartProfile(PKPROFILE Profile, SourceBuffer = ExAllocatePoolWithTag(NonPagedPool, sizeof(KPROFILE_SOURCE_OBJECT), 'forP'); + if (!SourceBuffer) return; RtlZeroMemory(SourceBuffer, sizeof(KPROFILE_SOURCE_OBJECT)); /* Raise to PROFILE_LEVEL */ diff --git a/reactos/ntoskrnl/mm/marea.c b/reactos/ntoskrnl/mm/marea.c index 7ac02d87140..7923faeff86 100644 --- a/reactos/ntoskrnl/mm/marea.c +++ b/reactos/ntoskrnl/mm/marea.c @@ -1006,7 +1006,9 @@ MmCreateMemoryArea(PMMSUPPORT AddressSpace, sizeof(MEMORY_AREA), TAG_MAREA); } - + + if (!MemoryArea) return STATUS_NO_MEMORY; + RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA)); MemoryArea->Type = Type; MemoryArea->StartingAddress = *BaseAddress; diff --git a/reactos/ntoskrnl/mm/region.c b/reactos/ntoskrnl/mm/region.c index c14b6bb142d..66a896597e4 100644 --- a/reactos/ntoskrnl/mm/region.c +++ b/reactos/ntoskrnl/mm/region.c @@ -245,6 +245,8 @@ MmInitializeRegion(PLIST_ENTRY RegionListHead, ULONG Length, ULONG Type, Region = ExAllocatePoolWithTag(NonPagedPool, sizeof(MM_REGION), TAG_MM_REGION); + if (!Region) return; + Region->Type = Type; Region->Protect = Protect; Region->Length = Length; diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index bec21e90e55..ab27cd9474e 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -2756,6 +2756,10 @@ ExeFmtpReadFile(IN PVOID File, Buffer = ExAllocatePoolWithTag(PagedPool, BufferSize, 'rXmM'); + if (!Buffer) + { + KeBugCheck(MEMORY_MANAGEMENT); + } UsedSize = 0; diff --git a/reactos/ntoskrnl/ob/oblink.c b/reactos/ntoskrnl/ob/oblink.c index c3b0c01e877..5b147474c0c 100644 --- a/reactos/ntoskrnl/ob/oblink.c +++ b/reactos/ntoskrnl/ob/oblink.c @@ -123,6 +123,7 @@ ObpParseSymbolicLink(IN PVOID ParsedObject, PWSTR NewTargetPath; ULONG LengthUsed, MaximumLength; NTSTATUS Status; + PAGED_CODE(); /* Assume failure */ *NextObject = NULL; @@ -169,6 +170,7 @@ ObpParseSymbolicLink(IN PVOID ParsedObject, NewTargetPath = ExAllocatePoolWithTag(NonPagedPool, MaximumLength, TAG_SYMLINK_TTARGET); + if (!NewTargetPath) return STATUS_INSUFFICIENT_RESOURCES; } else { diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index 71e6f419002..92237434fa6 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -969,6 +969,7 @@ PspTerminateThreadByPointer(IN PETHREAD Thread, /* Allocate the APC */ Apc = ExAllocatePoolWithTag(NonPagedPool, sizeof(KAPC), TAG_TERMINATE_APC); + if (!Apc) return STATUS_INSUFFICIENT_RESOURCES; /* Set the Terminated Flag */ Flags = Thread->CrossThreadFlags | CT_TERMINATED_BIT; diff --git a/reactos/ntoskrnl/se/semgr.c b/reactos/ntoskrnl/se/semgr.c index b5bbc02fb15..4ceaa19c4af 100644 --- a/reactos/ntoskrnl/se/semgr.c +++ b/reactos/ntoskrnl/se/semgr.c @@ -86,6 +86,8 @@ BOOLEAN NTAPI SepInitializationPhase0(VOID) { + PAGED_CODE(); + ExpInitLuid(); if (!SepInitSecurityIDs()) return FALSE; if (!SepInitDACLs()) return FALSE;