Skip to content

Commit c54a652

Browse files
authored
Fix #23610 - Stop parsing compressed DWARF sections ##crash
Parsing compressed DWARF sections as raw DWARF can lead to endless loops since content is invalid, leading to situations where an overly large total_entries value in parse_line_header_source_dwarf5 causes radare2 to busyloop.
1 parent 67b0e29 commit c54a652

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

libr/arch/include/elf/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@
381381
#define SHF_OS_NONCONFORMING (1 << 8) /* OS specific processing required */
382382
#define SHF_GROUP (1 << 9) /* Member of a section group */
383383
#define SHF_TLS (1 << 10) /* Thread local storage section */
384+
#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
384385

385386
/* #define SHF_MASKOS 0x0F000000 *//* OS-specific semantics */
386387
#define SHF_MASKOS 0x0FF00000 /* New value, Oct 4, 1999 Draft */

libr/bin/dwarf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* radare - LGPL - Copyright 2012-2024 - pancake, Fedor Sakharov */
22

33
#include <r_core.h>
4+
#include "format/elf/elf.h"
45

56
#define READ8(buf) \
67
(((buf) + sizeof (ut8) < buf_end) ? ((ut8 *)buf)[0] : 0); \
@@ -384,6 +385,12 @@ static RBinSection *getsection(RBin *bin, int sn) {
384385
}
385386
r_list_foreach (o->sections, iter, section) {
386387
if (strstr (section->name, name_str)) {
388+
#if R2_USE_NEW_ABI
389+
if (r_str_startswith (section->name, ".debug_") && R_BIN_ELF_SCN_IS_COMPRESSED (section->flags)) {
390+
R_LOG_WARN ("Compressed dwarf sections not yet supported");
391+
return NULL;
392+
}
393+
#endif
387394
if (strstr (section->name, "zdebug")) {
388395
R_LOG_WARN ("Compressed dwarf sections not yet supported");
389396
return NULL;

libr/bin/format/elf/elf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,6 +3747,9 @@ static void _store_bin_sections(ELFOBJ *eo, const RVector *elf_bin_sections) {
37473747
ptr->type = elf_section_type_tostring (section->type);
37483748
ptr->add = !eo->phdr; // Load sections if there is no PHDR
37493749
ptr->perm = elf_flags_to_section_perms (section->flags);
3750+
#if R2_USE_NEW_ABI
3751+
ptr->flags = section->flags;
3752+
#endif
37503753
#if 0
37513754
TODO: ptr->flags = elf_flags_tostring (section->flags);
37523755
#define SHF_WRITE (1 << 0) /* Writable */

libr/bin/format/elf/elf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define R_BIN_ELF_SCN_IS_EXECUTABLE(x) x & SHF_EXECINSTR
1313
#define R_BIN_ELF_SCN_IS_READABLE(x) x & SHF_ALLOC
1414
#define R_BIN_ELF_SCN_IS_WRITABLE(x) x & SHF_WRITE
15+
#define R_BIN_ELF_SCN_IS_COMPRESSED(x) x & SHF_COMPRESSED
16+
1517

1618
#define R_BIN_ELF_SYMTAB_SYMBOLS 1 << 0
1719
#define R_BIN_ELF_DYNSYM_SYMBOLS 1 << 1

libr/include/r_bin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ typedef struct r_bin_section_t {
303303
ut64 vaddr;
304304
ut64 paddr;
305305
ut32 perm;
306+
#if R2_USE_NEW_ABI
307+
ut32 flags;
308+
#endif
306309
const char *type;
307310
const char *arch;
308311
char *format;

0 commit comments

Comments
 (0)