Skip to content

Commit

Permalink
addressing comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed Dec 20, 2023
1 parent e0fe540 commit a81025d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 6 additions & 7 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6401,12 +6401,11 @@ def dump_chunks_heap(self, start: int, end: int, arena: GlibcArena, allow_unalig
heap_corrupted = chunk.base_address > end
should_process = self.should_process_chunk(chunk, min_size, max_size)

if not summary:
if chunk.base_address == arena.top:
if should_process:
gef_print(
f"{chunk!s} {LEFT_ARROW} {Color.greenify('top chunk')}")
break
if not summary and chunk.base_address == arena.top:
if should_process:
gef_print(
f"{chunk!s} {LEFT_ARROW} {Color.greenify('top chunk')}")
break

if heap_corrupted:
err("Corrupted heap, cannot continue.")
Expand All @@ -6432,7 +6431,7 @@ def should_process_chunk(self, chunk: GlibcChunk, min_size: int, max_size: int)
if chunk.size < min_size:
return False

if max_size > 0 and chunk.size > max_size:
if 0 < max_size < chunk.size:
return False

return True
Expand Down
14 changes: 14 additions & 0 deletions tests/commands/heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def test_cmd_heap_chunks_min_size_filter(self):
self.assertNoException(res)
self.assertIn("Chunk(addr=", res)

cmd = "heap chunks --min-size 1048576"
target = _target("heap")
self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target))
res = gdb_run_silent_cmd(cmd, target=target)
self.assertNoException(res)
self.assertNotIn("Chunk(addr=", res)

def test_cmd_heap_chunks_max_size_filter(self):
cmd = "heap chunks --max-size 160"
target = _target("heap")
Expand All @@ -119,6 +126,13 @@ def test_cmd_heap_chunks_max_size_filter(self):
self.assertNoException(res)
self.assertIn("Chunk(addr=", res)

cmd = "heap chunks --max-size 16"
target = _target("heap")
self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target))
res = gdb_run_silent_cmd(cmd, target=target)
self.assertNoException(res)
self.assertNotIn("Chunk(addr=", res)

def test_cmd_heap_bins_fast(self):
cmd = "heap bins fast"
before = ["set environment GLIBC_TUNABLES glibc.malloc.tcache_count=0"]
Expand Down

0 comments on commit a81025d

Please sign in to comment.