From 43fe0c8a1c60b68632f65219b0f1402d57dc3329 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 21 Mar 2018 09:40:33 -0400 Subject: [PATCH] memory: Protect against use-after-free --- qemu/memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qemu/memory.c b/qemu/memory.c index f7421ee6..fc54a32c 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -97,6 +97,7 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr) //shift remainder of array down over deleted pointer memmove(&uc->mapped_blocks[i], &uc->mapped_blocks[i + 1], sizeof(MemoryRegion*) * (uc->mapped_block_count - i)); mr->destructor(mr); + mr->ram_block = NULL; obj = OBJECT(mr); obj->ref = 1; obj->free = g_free; @@ -119,6 +120,7 @@ int memory_free(struct uc_struct *uc) mr->enabled = false; memory_region_del_subregion(get_system_memory(uc), mr); mr->destructor(mr); + mr->ram_block = NULL; obj = OBJECT(mr); obj->ref = 1; obj->free = g_free;