Skip to content

Commit 3d7e227

Browse files
committed
Add corrupted list check and more headers
1 parent 4924ac4 commit 3d7e227

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

librz/core/linux_heap_glibc.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ void GH(print_heap_chunk)(RzCore *core, GHT chunk) {
558558
* @param addr Base address of the chunk
559559
* @return RzHeapChunk struct pointer of the chunk
560560
*/
561-
RZ_API GH(RzHeapChunk) * GH(rz_get_heap_chunk_at_addr)(RzCore *core, ut64 addr) {
561+
RZ_API GH(RzHeapChunk) * GH(rz_get_heap_chunk_at_addr)(RzCore *core, GHT addr) {
562562
GH(RzHeapChunk) *cnk = RZ_NEW0(GH(RzHeapChunk));
563563
if (!cnk) {
564564
return NULL;
@@ -1377,9 +1377,26 @@ RZ_API RzList *GH(rz_get_bin_content_list)(RzCore *core, MallocState *main_arena
13771377
}
13781378
GH(RzHeapChunk) *cnk = RZ_NEW0(GH(RzHeapChunk));
13791379
if (!cnk) {
1380-
return 0;
1380+
return chunks;
1381+
}
1382+
GHT brk_start = GHT_MAX, brk_end = GHT_MAX, initial_brk = GHT_MAX;
1383+
GH(get_brks)
1384+
(core, &brk_start, &brk_end);
1385+
if (brk_start == GHT_MAX || brk_end == GHT_MAX) {
1386+
eprintf("No Heap section\n");
1387+
return chunks;
1388+
}
1389+
const int tcache = rz_config_get_i(core->config, "dbg.glibc.tcache");
1390+
if (tcache) {
1391+
const int fc_offset = rz_config_get_i(core->config, "dbg.glibc.fc_offset");
1392+
initial_brk = ((brk_start >> 12) << 12) + fc_offset;
1393+
} else {
1394+
initial_brk = (brk_start >> 12) << 12;
13811395
}
13821396
while (fw != head->fd) {
1397+
if (fw > main_arena->GH(top) || fw < initial_brk) {
1398+
break;
1399+
}
13831400
rz_io_read_at(core->io, fw, (ut8 *)cnk, sizeof(GH(RzHeapChunk)));
13841401
RzHeapChunkListItem *chunk = malloc(sizeof(RzHeapChunkListItem));
13851402
chunk->addr = fw;

librz/include/rz_core.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,21 @@ RZ_API void rz_core_sysenv_end(RzCore *core, const char *cmd);
772772

773773
RZ_API void rz_core_recover_vars(RzCore *core, RzAnalysisFunction *fcn, bool argonly);
774774

775-
/* linux_heap_glibc */
775+
/* linux_heap_glibc.c */
776776
RZ_API RzHeapChunk_64 *rz_get_heap_chunk_at_addr_64(RzCore *core, ut64 addr);
777777
RZ_API RzList *rz_get_bin_content_list_64(RzCore *core, MallocState *main_arena, int bin_num);
778778
RZ_API RzList *rz_get_arenas_list_64(RzCore *core, ut64 m_arena, MallocState *main_arena);
779779
RZ_API RzList *rz_get_heap_chunks_list_64(RzCore *core, MallocState *main_arena, ut64 m_arena, ut64 m_state);
780780
RZ_API bool rz_resolve_main_arena_64(RzCore *core, ut64 *m_arena);
781781
RZ_API bool rz_update_main_arena_64(RzCore *core, ut64 m_arena, MallocState *main_arena);
782782
RZ_API RzList *rz_get_tcache_list_64(RzCore *core, ut64 m_arena, MallocState *main_arena, bool main_thread_only);
783+
RZ_API RzHeapChunk_32 *rz_get_heap_chunk_at_addr_32(RzCore *core, ut32 addr);
784+
RZ_API RzList *rz_get_bin_content_list_32(RzCore *core, MallocState *main_arena, int bin_num);
783785
RZ_API RzList *rz_get_arenas_list_32(RzCore *core, ut32 m_arena, MallocState *main_arena);
786+
RZ_API RzList *rz_get_heap_chunks_list_32(RzCore *core, MallocState *main_arena, ut32 m_arena, ut32 m_state);
787+
RZ_API bool rz_resolve_main_arena_32(RzCore *core, ut32 *m_arena);
788+
RZ_API bool rz_update_main_arena_32(RzCore *core, ut32 m_arena, MallocState *main_arena);
789+
RZ_API RzList *rz_get_tcache_list_32(RzCore *core, ut32 m_arena, MallocState *main_arena, bool main_thread_only);
784790
// XXX dupe from rz_bin.h
785791
/* bin.c */
786792
#define RZ_CORE_BIN_ACC_STRINGS 0x001

0 commit comments

Comments
 (0)