Re: [DynInst_API:] segfault when trying to parse an ELF, dereferencing [0] in vector of size 0


Date: Thu, 11 Jan 2018 18:09:56 +0000
From: Bill Williams <bill@xxxxxxxxxxx>
Subject: Re: [DynInst_API:] segfault when trying to parse an ELF, dereferencing [0] in vector of size 0
Thomas--

We had a chance to discuss this a bit at our group meeting this morning. I think the simplest solution here is that, if no section headers are present, we should create a .text Region and a .data Region corresponding to the loadable RX and RW segments respectively, and the chunks of code that presume shdrs is a non-empty vector should be reworked to iterate/check appropriately and not go off into empty space. Creating those regions should put Symtab back on a sound footing for feeding the rest of the components.

Is this a binary you can share with us for testing purposes? Was it generated with strip -R or some less standard toolchain?

--bw
________________________________________
From: Dyninst-api <dyninst-api-bounces@xxxxxxxxxxx> on behalf of Thomas Dullien <thomasdullien@xxxxxxxxxx>
Sent: Thursday, January 11, 2018 4:45 AM
To: dyninst-api
Subject: Re: [DynInst_API:] segfault when trying to parse an ELF, dereferencing [0] in vector of size 0

Hey there,

a quick update: The issue seems to be that the ELF file has legitimate shdrnum=0 in the header,
which some of the other code is not prepared for.

Cheers,
Thomas

On Thu, Jan 11, 2018 at 11:36 AM, Thomas Dullien <thomasdullien@xxxxxxxxxx<mailto:thomasdullien@xxxxxxxxxx>> wrote:
Hey there,

I am trying to run a particular ELF file through Dyninst, but I get a segfault
in Elf_X.C:

if (!shdrs[i]._elf) {

The trouble is that shdrs is an empty vector, and i is 0, so we can't dereference
at index 0.

#0  Dyninst::Elf_X::get_shdr (this=this@entry=0x557c15ecf0a0, i=0) at /home/thomasdullien/Desktop/sources/dyninst/dyninst/elf/src/Elf_X.C:473
#1  0x00007fd72b83f43a in Dyninst::Elf_X::findDebugFile (this=0x557c15ecf0a0, origfilename="/home/thomasdullien/Downloads/foo.elf", output_name="", output_buffer=@0x7fff5398c320: 0x557c15ecf470 "/home/thomasdullien/Downloads/foo.elf", output_buffer_size=@0x7fff5398c
328: 93991432156048) at /home/thomasdullien/Desktop/sources/dyninst/dyninst/elf/src/Elf_X.C:1659
#2  0x00007fd72ba5b124 in Dyninst::Dwarf::DwarfHandle::locate_dbg_file (this=this@entry=0x557c15ecf3d0) at /home/thomasdullien/Desktop/sources/dyninst/dyninst/dwarf/src/dwarfHandle.C:80
#3  0x00007fd72ba5b29f in Dyninst::Dwarf::DwarfHandle::DwarfHandle (this=0x557c15ecf3d0, filename_=..., file_=<optimized out>, err_func_=<optimized out>) at /home/thomasdullien/Desktop/sources/dyninst/dyninst/dwarf/src/dwarfHandle.C:73
#4  0x00007fd72ba5b9ff in Dyninst::Dwarf::DwarfHandle::createDwarfHandle (filename_="/home/thomasdullien/Downloads/foo.elf", file_=file_@entry=0x557c15ecf0a0, err_func_=err_func_@entry=0x7fd72ba5b010 <Dyninst::Dwarf::DwarfHandle::defaultDwarfError(Dwarf_Error_s*, void*
)>) at /home/thomasdullien/Desktop/sources/dyninst/dyninst/dwarf/src/dwarfHandle.C:249

Shall I try to dig further, or should this be sufficient to find the problem?

Cheers & keep up the good work :-)
Thomas



[← Prev in Thread] Current Thread [Next in Thread→]