[PATCH] libdw: Don't crash on invalid die in dwarf_dieoffset.

Mark Wielaard mark@klomp.org
Thu May 31 17:52:00 GMT 2018


On Thu, May 31, 2018 at 01:02:44PM +0200, Mark Wielaard wrote:
> Add explicit test in get-units-invalid for dwarf_cuoffset and
> dwarf_dieoffset.

And that test caught another bug on 32bit systems!

>  Dwarf_Off
>  dwarf_dieoffset (Dwarf_Die *die)
>  {
> -  return (die == NULL
> +  return ((die == NULL || die->cu == NULL)
>  	  ? ~0ul
>  	  : (Dwarf_Off) (die->addr - die->cu->startp + die->cu->start));

Note that ~0ul != (Dwarf_Off) -1 on 32bit systems.
So error detection was always broken.

The reason we didn't notice before was because we had a similar bug
in eu-readelf...

I am checking in the attached patch which fixes both.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libdw-Don-t-crash-on-invalid-die-in-dwarf_dieoffset.patch
Type: text/x-diff
Size: 3401 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/elfutils-devel/attachments/20180531/5e684017/attachment.bin>


More information about the Elfutils-devel mailing list