[Bug libbacktrace/81983] libbacktrace calls bsearch with NULL base

vries at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Feb 12 14:01:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81983

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
Author: vries
Date: Tue Feb 12 14:00:59 2019
New Revision: 268796

URL: https://gcc.gnu.org/viewcvs?rev=268796&root=gcc&view=rev
Log:
[libbacktrace] Handle bsearch with NULL base in dwarf_lookup_pc

The call to bsearch in dwarf_lookup_pc can have NULL as base argument when
the nmemb argument is 0.  The base argument is required to be pointing to the
initial member of an array of nmemb objects.  It is not specified what
constitutes a valid pointer to an array of 0 objects, but glibc declares base
with attribute non-null, so the NULL will trigger a sanitizer runtime error.

Fix this by only calling bsearch if nmemb != 0.

2019-02-12  Tom de Vries  <tdevries@suse.de>

        PR libbacktrace/81983
        * dwarf.c (dwarf_lookup_pc): Don't call bsearch if nmemb == 0.

Modified:
    trunk/libbacktrace/ChangeLog
    trunk/libbacktrace/dwarf.c


More information about the Gcc-bugs mailing list