]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdw: Simplify __libdw_getabbrev and fix dwarf_offabbrev issue
authorMark Wielaard <mark@klomp.org>
Sat, 8 Feb 2025 19:00:12 +0000 (20:00 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 14 Feb 2025 07:55:10 +0000 (08:55 +0100)
commit2636426a091bd6c6f7f02e49ab20d4cdc6bfc753
tree5481ea44bbc5d867580d1e45b8c24dc9bb0eca0e
parent316077dd4b34c90f7e4c4228395a580e99239347
libdw: Simplify __libdw_getabbrev and fix dwarf_offabbrev issue

__libdw_getabbrev could crash on reading a bad abbrev by trying to
deallocate memory it didn't allocate itself. This could happen because
dwarf_offabbrev would supply its own memory when calling
__libdw_getabbrev. No other caller did this.

Simplify the __libdw_getabbrev common code by not taking external
memory to put the abbrev result in (this would also not work correctly
if the abbrev was already cached). And make dwarf_offabbrev explicitly
copy the result (if there was no error or end of abbrev).

     * libdw/dwarf_getabbrev.c (__libdw_getabbrev): Don't take
     Dwarf_Abbrev result argument. Always just allocate abb when
     abbrev not found in cache.
     (dwarf_getabbrev): Don't pass NULL as last argument to
     __libdw_getabbrev.
    * libdw/dwarf_tag.c (__libdw_findabbrev): Likewise.
    * libdw/dwarf_offabbrev.c (dwarf_offabbrev): Likewise. And copy
    abbrev into abbrevp on success.
    * libdw/libdw.h (dwarf_offabbrev): Document return values.
    * libdw/libdwP.h (__libdw_getabbrev): Don't take Dwarf_Abbrev
    result argument.

https://sourceware.org/bugzilla/show_bug.cgi?id=32650

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/dwarf_getabbrev.c
libdw/dwarf_offabbrev.c
libdw/dwarf_tag.c
libdw/libdw.h
libdw/libdwP.h