Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always print top chunk when run heap chunks -a #1170

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6690,11 +6690,13 @@ def do_invoke(self, _: list[str], **kwargs: Any) -> None:
if not args.all:
return
try:
if not args.arena_address:
return
arena_addr = parse_address(args.arena_address)
arena = GlibcArena(f"*{arena_addr:#x}")
self.dump_chunks_arena(arena, ctx)
except gdb.error:
err("Invalid arena")
except gdb.error as e:
err(f"Invalid arena: {e} \nArena Address: {args.arena_address}")
return

def dump_chunks_arena(self, arena: GlibcArena, ctx: GlibcHeapWalkContext) -> None:
Expand All @@ -6718,6 +6720,7 @@ def dump_chunks_heap(self, start: int, end: int, arena: GlibcArena, ctx: GlibcHe
nb = self["peek_nb_byte"]
chunk_iterator = GlibcChunk(start, from_base=True, allow_unaligned=ctx.allow_unaligned)
heap_summary = GlibcHeapArenaSummary(resolve_type=ctx.resolve_type)
top_printed = False
for chunk in chunk_iterator:
heap_corrupted = chunk.base_address > end
should_process = self.should_process_chunk(chunk, ctx)
Expand All @@ -6726,6 +6729,8 @@ def dump_chunks_heap(self, start: int, end: int, arena: GlibcArena, ctx: GlibcHe
if should_process:
gef_print(
f"{chunk!s} {LEFT_ARROW} {Color.greenify('top chunk')}")

top_printed = True
break

if heap_corrupted:
Expand All @@ -6748,6 +6753,9 @@ def dump_chunks_heap(self, start: int, end: int, arena: GlibcArena, ctx: GlibcHe

ctx.remaining_chunk_count -= 1

if not top_printed and ctx.print_arena:
top_chunk = GlibcChunk(arena.top, from_base=True, allow_unaligned=ctx.allow_unaligned)
gef_print(f"{top_chunk!s} {LEFT_ARROW} {Color.greenify('top chunk')}")
if ctx.summary:
heap_summary.print()

Expand Down