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.
This commit is contained in:
Disconnect3d 2023-05-12 11:02:59 +02:00 committed by GitHub
parent 3bc91c1cb2
commit e77c6f5c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -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