Menu

#556 libdwarf segfault while attempting to relocate SHT_NOBITS section

RELEASE_1_0
new
nobody
None
2017-12-24
2017-12-24
Ryan Stone
No

I get a crash in _dwarf_elfrelocate from this call to malloc() on certain ELF files:

memcpy(ed->ed_alloc, ed->ed_data->d_buf,
                ed->ed_data->d_size);

ed->ed_data->d_buf winds up being NULL because the section is an SHT_NOBITS section.

The backtrace looks like:

#0  memcpy () at /usr/home/rstone/git/freebsd/lib/libc/amd64/string/bcopy.S:65
#1  0x000000080084ac38 in _dwarf_elf_relocate (elf=<optimized out>, 
    shndx=<optimized out>, error=<optimized out>, dbg=<optimized out>, 
    ed=<optimized out>, symtab=<optimized out>, symtab_data=<optimized out>)
    at /usr/home/rstone/git/freebsd/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c:176
#2  _dwarf_elf_init (dbg=<optimized out>, elf=0x800692000, error=0x7fffffffe008)
    at /usr/home/rstone/git/freebsd/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c:342
#3  0x00000008008448b1 in dwarf_init (fd=<optimized out>, mode=<optimized out>, 
    errhand=0x0, errarg=0x0, ret_dbg=0x7fffffffe488, error=0x7fffffffe008)
    at /usr/home/rstone/git/freebsd/contrib/elftoolchain/libdwarf/dwarf_init.c:119
#4  0x0000000000401ff2 in main (argc=4, argv=0x7fffffffe528)
    at /usr/home/rstone/git/freebsd/contrib/elftoolchain/addr2line/addr2line.c:709[](http://)

The attached patch works around the crash for me, but I'm not sure whether it is actually correct.

1 Attachments

Discussion


Log in to post a comment.