From 107a8f1bac48435ce857c371934695332d587aff Mon Sep 17 00:00:00 2001 From: davi Date: Sun, 6 Apr 2025 07:38:22 -0300 Subject: [PATCH] hexdump: check if address is valid (#2833) --- pwndbg/commands/hexdump.py | 3 +++ tests/gdb-tests/tests/test_hexdump.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pwndbg/commands/hexdump.py b/pwndbg/commands/hexdump.py index 2859cdfb1..e2a4daeeb 100644 --- a/pwndbg/commands/hexdump.py +++ b/pwndbg/commands/hexdump.py @@ -77,6 +77,9 @@ def hexdump(address, count=pwndbg.config.hexdump_bytes) -> None: hexdump.offset = 0 address = int(address) + if not pwndbg.aglib.memory.peek(address): + print("Could not read memory at specified address") + return if address > pwndbg.aglib.arch.ptrmask: new_address = address & pwndbg.aglib.arch.ptrmask print( diff --git a/tests/gdb-tests/tests/test_hexdump.py b/tests/gdb-tests/tests/test_hexdump.py index 4f4859227..5abc6cc69 100644 --- a/tests/gdb-tests/tests/test_hexdump.py +++ b/tests/gdb-tests/tests/test_hexdump.py @@ -21,7 +21,7 @@ def run_tests(stack, use_big_endian, expected): # Test empty hexdump result = gdb.execute("hexdump 0", to_string=True) - assert result == "+0000 0x000000 \n" + assert result == "Could not read memory at specified address\n" results = [] # TODO: Repetition is not working in tests