From 8dae55490b0870107f643592e91ad6900da980ac Mon Sep 17 00:00:00 2001 From: CptGibbon <16000770+CptGibbon@users.noreply.github.com> Date: Wed, 14 Sep 2022 09:01:15 -0700 Subject: [PATCH] Add gdb.MemoryError check to get_heap() (#1145) Call fetch_lazy() on the gdb.Value acquired in get_heap() and wrap it in a try/except block. Return None if gdb.MemoryError is raised. Let get_arena_for_chunk() handle None returned by get_heap(). Fixes #1142 --- pwndbg/heap/ptmalloc.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pwndbg/heap/ptmalloc.py b/pwndbg/heap/ptmalloc.py index 7a715861..226dc8c2 100644 --- a/pwndbg/heap/ptmalloc.py +++ b/pwndbg/heap/ptmalloc.py @@ -307,7 +307,8 @@ class Heap(pwndbg.heap.heap.BaseHeap): chunk = pwndbg.commands.heap.read_chunk(addr) _, _, nm = self.chunk_flags(chunk["size"]) if nm: - r = self.get_arena(arena_addr=self.get_heap(addr)["ar_ptr"]) + h = self.get_heap(addr) + r = self.get_arena(h["ar_ptr"]) if h else None else: r = self.main_arena return r @@ -634,7 +635,13 @@ class DebugSymsHeap(Heap): def get_heap(self, addr): """Find & read the heap_info struct belonging to the chunk at 'addr'.""" - return pwndbg.gdblib.memory.poi(self.heap_info, heap_for_ptr(addr)) + try: + r = pwndbg.gdblib.memory.poi(self.heap_info, heap_for_ptr(addr)) + r.fetch_lazy() + except gdb.MemoryError: + r = None + + return r def get_arena(self, arena_addr=None): """Read a malloc_state struct from the specified address, default to