diff --git a/gef.py b/gef.py index 08d193ab5..14952f97a 100644 --- a/gef.py +++ b/gef.py @@ -6981,6 +6981,11 @@ def tcachebin(self, tcache_base: int, i: int) -> tuple[GlibcTcacheChunk | None, count = u16(gef.memory.read(tcache_base + tcache_count_size*i, 2)) chunk = dereference(tcache_base + tcache_count_size*self.TCACHE_MAX_BINS + i*gef.arch.ptrsize) + + # Real heap chunk pointers are always ptrsize-aligned, so we check + # the alignment to prevent following invalid addresses. + if chunk and (int(chunk) & (gef.arch.ptrsize - 1)): + return None, count chunk = GlibcTcacheChunk(int(chunk)) if chunk else None return chunk, count diff --git a/tests/commands/heap.py b/tests/commands/heap.py index d6a70e042..6073c22d4 100644 --- a/tests/commands/heap.py +++ b/tests/commands/heap.py @@ -9,7 +9,6 @@ ERROR_INACTIVE_SESSION_MESSAGE, debug_target, findlines, - is_glibc_ge, is_32b, is_64b, ) @@ -22,7 +21,6 @@ def setUp(self) -> None: self._target = debug_target("heap") return super().setUp() - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_arenas(self): gdb = self._gdb cmd = "heap arenas" @@ -34,7 +32,6 @@ def test_cmd_heap_arenas(self): res = gdb.execute(cmd, to_string=True) self.assertIn("Arena(base=", res) - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_set_arena(self): gdb = self._gdb cmd = "heap set-arena &main_arena" @@ -70,7 +67,6 @@ def test_cmd_heap_chunk_with_number(self): chunklines = findlines("Chunk(addr=", res) self.assertEqual(len(chunklines), 2) - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_chunks(self): gdb = self._gdb cmd = "heap chunks" @@ -95,7 +91,6 @@ def test_cmd_heap_chunks_summary(self): self.assertIn("== Chunk distribution by size", res) self.assertIn("== Chunk distribution by flag", res) - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_chunks_min_size_filter(self): gdb = self._gdb self.assertEqual( @@ -153,7 +148,6 @@ def setUp(self) -> None: self._target = debug_target("heap-non-main") return super().setUp() - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_chunks(self): gdb = self._gdb cmd = "heap chunks" @@ -175,7 +169,6 @@ def test_cmd_heap_chunks(self): # make sure that the chunks of each arena are distinct self.assertNotEqual(chunks, non_main_chunks) - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_bins_non_main(self): gdb = self._gdb gef = self._gef @@ -188,7 +181,6 @@ def test_cmd_heap_bins_non_main(self): self.assertIn("size=0x20", res) @pytest.mark.skipif(ARCH not in ("i686", "x86_64",), reason=f"Skipped for {ARCH}") - @pytest.mark.skipif(is_glibc_ge(2, 42), reason="Skipped for glibc >= 2.42") def test_cmd_heap_bins_tcache(self): gdb = self._gdb gdb.execute("run") @@ -210,7 +202,6 @@ def setUp(self) -> None: self._target = debug_target("heap-multiple-heaps") return super().setUp() - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_chunks_mult_heaps(self): gdb = self._gdb @@ -268,7 +259,6 @@ def setUp(self) -> None: self.expected_unsorted_bin_size = 0x430 if ARCH == "i686" or is_64b() else 0x428 return super().setUp() - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_bins_large(self): gdb = self._gdb gdb.execute("run") @@ -278,7 +268,6 @@ def test_cmd_heap_bins_large(self): self.assertIn("Chunk(addr=", res) self.assertIn(f"size={self.expected_large_bin_size:#x}", res) - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_bins_small(self): gdb = self._gdb cmd = "heap bins small" @@ -289,7 +278,6 @@ def test_cmd_heap_bins_small(self): self.assertIn("Chunk(addr=", res) self.assertIn(f"size={self.expected_small_bin_size:#x}", res) - @pytest.mark.skipif(is_glibc_ge(2, 43), reason="Skipped for glibc >= 2.43") def test_cmd_heap_bins_unsorted(self): gdb = self._gdb gdb.execute("run") @@ -307,7 +295,6 @@ def setUp(self) -> None: return super().setUp() @pytest.mark.skipif(ARCH not in ("i686", "x86_64"), reason=f"Skipped for {ARCH}") - @pytest.mark.skipif(is_glibc_ge(2, 42), reason="Skipped for glibc >= 2.42") def test_cmd_heap_bins_tcache_all(self): gdb = self._gdb gdb.execute("run")