fix(jemalloc): More gracefully handle cmd failure due to missing types/symbols (#2527)

pull/2554/head
Aaron Adams 1 year ago committed by GitHub
parent 74838520dc
commit 8955a1170a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1588,6 +1588,7 @@ def jemalloc_find_extent(addr) -> None:
addr = int(addr)
try:
rtree = jemalloc.RTree.get_rtree()
extent = rtree.lookup_hard(addr)
if extent is None:
@ -1599,6 +1600,9 @@ def jemalloc_find_extent(addr) -> None:
print()
jemalloc_extent_info(extent.extent_address, header=False)
except pwndbg.dbg_mod.Error as e:
print(message.error(f"ERROR: {e}"))
return
parser = argparse.ArgumentParser(description="Prints extent information for the given address")
@ -1609,12 +1613,13 @@ parser.add_argument(
@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.HEAP)
def jemalloc_extent_info(addr, verbose=False, header=True) -> None:
def jemalloc_extent_info(addr, verbose=False, header=True) -> bool:
if header:
print(C.banner("Jemalloc extent info"))
print("This command was tested only for jemalloc 5.3.0 and does not support lower versions")
print()
try:
extent = jemalloc.Extent(int(addr))
print(f"Allocated Address: {hex(extent.allocated_address)}")
@ -1628,6 +1633,10 @@ def jemalloc_extent_info(addr, verbose=False, header=True) -> None:
if verbose:
for bit, val in extent.bitfields.items():
print(bit, val)
except pwndbg.dbg_mod.Error as e:
print(message.error(f"ERROR: {e}"))
return False
return True
parser = argparse.ArgumentParser(description="Prints all extents information")
@ -1641,17 +1650,15 @@ def jemalloc_heap() -> None:
try:
rtree = jemalloc.RTree.get_rtree()
except pwndbg.dbg_mod.Error as what:
# Fixes test_commands[jemalloc_heap] test case
print(message.warn(f"{what}"))
return
extents = rtree.extents
if len(extents) == 0:
print(message.warn("No extents found"))
return
for extent in extents:
# TODO: refactor so not create copies
jemalloc_extent_info(extent.extent_address, header=False)
if not jemalloc_extent_info(extent.extent_address, header=False):
return
print()
except pwndbg.dbg_mod.Error as e:
print(message.error(f"ERROR: {e}"))
return

Loading…
Cancel
Save