From 398838e6c3ea3e5ad2c5171d351f77ae12ebfb33 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Mon, 14 Sep 2009 09:21:05 +0000 Subject: [PATCH] NtAllocateVirtualMemory: Add check to make sure that BaseAddress + RegionSize is inside MemoryArea. For AllocationType of MEM_RESET add FIXME's and return STATUS_SUCCESS, without modifying attributes of region. Fixes 2 virtual tests for kernel32_winetest. svn path=/trunk/; revision=43049 --- reactos/ntoskrnl/mm/anonmem.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/reactos/ntoskrnl/mm/anonmem.c b/reactos/ntoskrnl/mm/anonmem.c index 46d85569d2f..8b985853a55 100644 --- a/reactos/ntoskrnl/mm/anonmem.c +++ b/reactos/ntoskrnl/mm/anonmem.c @@ -729,6 +729,36 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle, { MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress - (ULONG_PTR)MemoryArea->StartingAddress; + + if (((ULONG)BaseAddress + RegionSize) > (ULONG)MemoryArea->EndingAddress) + { + DPRINT("BaseAddress + RegionSize %x is larger than MemoryArea's EndingAddress %x\n", + (ULONG)BaseAddress + RegionSize, MemoryArea->EndingAddress); + + MmUnlockAddressSpace(AddressSpace); + ObDereferenceObject(Process); + + return STATUS_MEMORY_NOT_ALLOCATED; + } + + if (AllocationType == MEM_RESET) + { + if (MmIsPagePresent(Process, BaseAddress)) + { + /* FIXME: mark pages as not modified */ + } + else + { + /* FIXME: if pages are in paging file discard them and bring in pages of zeros */ + } + + MmUnlockAddressSpace(AddressSpace); + ObDereferenceObject(Process); + + /* MEM_RESET does not modify any attributes of region */ + return STATUS_SUCCESS; + } + if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY && MemoryAreaLength >= RegionSize) {