Skip to content

Commit

Permalink
Fix loading symbols from nested ELF ##bin (#18615)
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Apr 21, 2021
1 parent c3aafd6 commit 07be57f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libr/bin/format/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,7 @@ static int cmp_RBinElfSymbol(const RBinElfSymbol *a, const RBinElfSymbol *b) {
return strcmp (a->type, b->type);
}

static RBinElfSymbol* parse_gnu_debugdata(ELFOBJ *bin) {
static RBinElfSymbol* parse_gnu_debugdata(ELFOBJ *bin, size_t *ret_size) {
if (bin->g_sections) {
size_t i;
for (i = 0; !bin->g_sections[i].last; i++) {
Expand All @@ -3494,11 +3494,12 @@ static RBinElfSymbol* parse_gnu_debugdata(ELFOBJ *bin) {
if (odata) {
RBuffer *newelf = r_buf_new_with_pointers (odata, osize, false);
ELFOBJ* newobj = Elf_(r_bin_elf_new_buf)(newelf, false);
struct r_bin_elf_symbol_t *symbol = Elf_(r_bin_elf_get_symbols) (newobj);
RBinElfSymbol *symbol = Elf_(r_bin_elf_get_symbols) (newobj);
newobj->g_symbols = NULL;
Elf_(r_bin_elf_free)(newobj);
r_buf_free (newelf);
free (odata);
*ret_size = i;
return symbol;
}
free (data);
Expand Down Expand Up @@ -3542,9 +3543,10 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type
if (shdr_size + 8 > bin->size) {
return NULL;
}
RBinElfSymbol *dbgsyms = parse_gnu_debugdata (bin);
RBinElfSymbol *dbgsyms = parse_gnu_debugdata (bin, &ret_size);
if (dbgsyms) {
ret = dbgsyms;
ret_ctr = ret_size;
}
for (i = 0; i < bin->ehdr.e_shnum; i++) {
if (((type & R_BIN_ELF_SYMTAB_SYMBOLS) && bin->shdr[i].sh_type == SHT_SYMTAB) ||
Expand Down

0 comments on commit 07be57f

Please sign in to comment.