From: John Hodge Date: Sun, 6 Oct 2013 11:12:20 +0000 (+0800) Subject: Kernel - Added catch in Heap_Allocate for 0-sized blocks X-Git-Tag: rel0.15~135 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9567f04210ad92b4d991c137527fa5253c968aad;p=tpg%2Facess2.git Kernel - Added catch in Heap_Allocate for 0-sized blocks --- 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;