Skip to content

Commit

Permalink
Fix recursive loop on architectures where flags register is a dynam…
Browse files Browse the repository at this point in the history
…ic value (#1065)

## Description

For (at least) ARM and ARM64`$arch.ptrsize` is calculated dynamically from CSPR flags, and invokes `parse_address`. However, `parse_address` requires `ptrsize` to be set to determine the alignment. So we end up in an infinite loop. Which breaks almost everything.

This commit fixes it by simply replacing `to_unsigned_long` with `int` is perfectly fine for this situation, which is what the PR does.
  • Loading branch information
hugsy authored Feb 2, 2024
1 parent 4c307e6 commit db5b7b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -3841,7 +3841,7 @@ def parse_address(address: str) -> int:
"""Parse an address and return it as an Integer."""
if is_hex(address):
return int(address, 16)
return to_unsigned_long(gdb.parse_and_eval(address))
return int(gdb.parse_and_eval(address))


def is_in_x86_kernel(address: int) -> bool:
Expand Down
9 changes: 6 additions & 3 deletions tests/commands/entry_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ def test_cmd_entry_break(self):
gdb = self._gdb

# run once (ok)
res = gdb.execute("entry-break", to_string=True).strip()
assert res.startswith("[+] Breaking at")
lines = (gdb.execute("entry-break", to_string=True) or "").strip().splitlines()

# expect the entry point string pattern
assert len(lines) >= 2
assert any(line.startswith("[+] Breaking at entry-point") for line in lines)

# re-run while session running (nok)
res = gdb.execute("entry-break", to_string=True).strip()
res = (gdb.execute("entry-break", to_string=True) or "").strip()
assert "gdb is already running" in res
14 changes: 7 additions & 7 deletions tests/commands/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ class HighlightCommand(RemoteGefUnitTestGeneric):
def test_cmd_highlight(self):
gdb = self._gdb

gdb.execute("start")

gdb.execute("gef config context.layout stack")
gdb.execute("gef config gef.disable_color 0")
gdb.execute("start")

for cmd in [
"highlight add 41414141 yellow",
"highlight add 42424242 blue",
"highlight add 43434343 green",
"highlight add 44444444 pink",
'patch string $sp "AAAABBBBCCCCDDDD"',
"hexdump qword $sp -s 2",
]:
gdb.execute(cmd)

res = gdb.execute("context", to_string=True)
self.assertIn(f"{Color.YELLOW.value}41414141{Color.NORMAL.value}", res)
self.assertIn(f"{Color.BLUE.value}42424242{Color.NORMAL.value}", res)
self.assertIn(f"{Color.GREEN.value}43434343{Color.NORMAL.value}", res)
self.assertIn(f"{Color.PINK.value}44444444{Color.NORMAL.value}", res)
res: str = (gdb.execute("hexdump qword $sp -s 2", to_string=True) or "").strip()
assert f"{Color.YELLOW.value}41414141{Color.NORMAL.value}" in res
assert f"{Color.BLUE.value}42424242{Color.NORMAL.value}" in res
assert f"{Color.GREEN.value}43434343{Color.NORMAL.value}" in res
assert f"{Color.PINK.value}44444444{Color.NORMAL.value}" in res

0 comments on commit db5b7b8

Please sign in to comment.