From e77c6f5c2e0d23b5073eb035076e280ec5ef84c3 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Fri, 12 May 2023 11:02:59 +0200 Subject: [PATCH] Fix stack.update caching bug (#1703) The `pwndbg.gdblib.regs.sp` value is cached and its cache is cleared on a next stop, memory write or register write events. We keep a dictionary of stacks in Pwndbg, that are updated on each stop by the `stack.update` functionality which reused a cached stack pointer (`gdblib.regs.sp`) value. As a result, if we had more than one threads, the `pwndbg.gdblib.stacks.stacks` reported the same stack address for all threads and then the `canary` command printed the same addresses N times where N is the number of threads that were running. This commit fixes this bug by clearing up the registers cache when we switch into a different thread in the loop in the `stacks.update` function. --- pwndbg/gdblib/stack.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pwndbg/gdblib/stack.py b/pwndbg/gdblib/stack.py index a9de9fec1..e2ac228ca 100644 --- a/pwndbg/gdblib/stack.py +++ b/pwndbg/gdblib/stack.py @@ -62,6 +62,7 @@ def update() -> None: try: for thread in gdb.selected_inferior().threads(): thread.switch() + pwndbg.gdblib.regs.__getattr__.cache.clear() sp = pwndbg.gdblib.regs.sp # Skip if sp is None or 0