libroot/malloc: Make the guarded heap handle bogus pointers better.
* Check if the area is a stack, and panic() if so. * Check names before accessing any area, and don't try to do anything with areas that we didn't create. Makes frees pointing to stack data have much more useful diagnostics than just "generic segfault".
This commit is contained in:
@@ -714,6 +714,15 @@ guarded_heap_area_allocation_for(void* address, area_id& allocationArea)
|
||||
if (get_area_info(allocationArea, &areaInfo) != B_OK)
|
||||
return NULL;
|
||||
|
||||
if ((areaInfo.protection & B_STACK_AREA) != 0) {
|
||||
panic("tried to free %p which is in a stack area (%d)",
|
||||
address, allocationArea);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strncmp(areaInfo.name, "guarded_heap", strlen("guarded_heap")) != 0)
|
||||
return NULL;
|
||||
|
||||
guarded_heap_page* page = (guarded_heap_page*)areaInfo.address;
|
||||
if (page->flags != (GUARDED_HEAP_PAGE_FLAG_USED
|
||||
| GUARDED_HEAP_PAGE_FLAG_FIRST | GUARDED_HEAP_PAGE_FLAG_AREA)) {
|
||||
|
||||
Reference in New Issue
Block a user