From 456440d329ff2b4af535a0fbc20e9ed2e18786b9 Mon Sep 17 00:00:00 2001 From: billow Date: Sat, 21 Oct 2023 16:21:48 +0800 Subject: [PATCH] Fix heap-use-after-free --- librz/bin/dwarf/endian_reader.c | 3 ++- librz/core/cdwarf.c | 2 +- librz/include/rz_bin_dwarf.h | 2 +- test/db/cmd/dwarf | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/librz/bin/dwarf/endian_reader.c b/librz/bin/dwarf/endian_reader.c index d4b081c258f..da00d99a65c 100644 --- a/librz/bin/dwarf/endian_reader.c +++ b/librz/bin/dwarf/endian_reader.c @@ -144,7 +144,7 @@ RZ_IPI RzBinEndianReader *RzBinEndianReader_from_file(RzBinFile *binfile, const reader->buffer = buf; reader->big_endian = bf_bigendian(binfile); - reader->section = section; + reader->section_name = rz_str_new(section->name); reader->relocations = relocations; return reader; } @@ -258,6 +258,7 @@ RZ_IPI void RzBinEndianReader_free(RzBinEndianReader *r) { } rz_buf_free(r->buffer); ht_up_free(r->relocations); + free(r->section_name); free(r); } diff --git a/librz/core/cdwarf.c b/librz/core/cdwarf.c index 9af085de024..15e4c1284ef 100644 --- a/librz/core/cdwarf.c +++ b/librz/core/cdwarf.c @@ -426,7 +426,7 @@ RZ_API RZ_OWN char *rz_core_bin_dwarf_line_units_to_string(RZ_NONNULL RZ_BORROW if (!sb) { return NULL; } - rz_strbuf_appendf(sb, "Raw dump of debug contents of section %s:\n\n", line->reader->section->name); + rz_strbuf_appendf(sb, "Raw dump of debug contents of section %s:\n\n", line->reader->section_name); RzListIter *it; RzBinDwarfLineUnit *unit; bool first = true; diff --git a/librz/include/rz_bin_dwarf.h b/librz/include/rz_bin_dwarf.h index 1c04c79ff85..2539a68680f 100644 --- a/librz/include/rz_bin_dwarf.h +++ b/librz/include/rz_bin_dwarf.h @@ -972,7 +972,7 @@ struct rz_bin_section_t; typedef struct { RzBuffer *buffer; bool big_endian; - const struct rz_bin_section_t *section; + char *section_name; HtUP *relocations; } RzBinEndianReader; diff --git a/test/db/cmd/dwarf b/test/db/cmd/dwarf index cbb69e70854..1b0e1c646ca 100644 --- a/test/db/cmd/dwarf +++ b/test/db/cmd/dwarf @@ -6894,7 +6894,7 @@ paddr size vaddr vsize align perm name type flags <0x14d>: Abbrev Number: 2 (DW_TAG_pointer_type) DW_AT_type [DW_FORM_ref4] : <0x13a> <0x152>: Abbrev Number: 0 (DW_TAG_null_entry) -Raw dump of debug contents of section (null): +Raw dump of debug contents of section .debug_line: Header information[0x0] Length: 351