Kernel - Added catch in Heap_Allocate for 0-sized blocks
authorJohn Hodge <[email protected]>
Sun, 6 Oct 2013 11:12:20 +0000 (19:12 +0800)
committerJohn Hodge <[email protected]>
Sun, 6 Oct 2013 11:12:20 +0000 (19:12 +0800)
KernelLand/Kernel/heap.c

index be8eeaf..1794ac3 100644 (file)
@@ -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;

UCC git Repository :: git.ucc.asn.au