From 9567f04210ad92b4d991c137527fa5253c968aad Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 6 Oct 2013 19:12:20 +0800 Subject: [PATCH 1/1] Kernel - Added catch in Heap_Allocate for 0-sized blocks --- KernelLand/Kernel/heap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/KernelLand/Kernel/heap.c b/KernelLand/Kernel/heap.c index be8eeaf6..1794ac35 100644 --- a/KernelLand/Kernel/heap.c +++ b/KernelLand/Kernel/heap.c @@ -188,6 +188,20 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) #endif return NULL; } + if( head->Size < MIN_SIZE ) { + Mutex_Release(&glHeap); + Log_Warning("Heap", "Size of heap address %p is invalid - Too small (0x%x) [at paddr 0x%x]", + head, head->Size, MM_GetPhysAddr(&head->Size)); + Heap_Dump(); + return NULL; + } + if( head->Size > (2<<30) ) { + Mutex_Release(&glHeap); + Log_Warning("Heap", "Size of heap address %p is invalid - Over 2GiB (0x%x) [at paddr 0x%x]", + head, head->Size, MM_GetPhysAddr(&head->Size)); + Heap_Dump(); + return NULL; + } // Check if allocated if(head->Magic == MAGIC_USED) continue; -- 2.20.1