[libbacktrace] Handle bsearch with NULL base in dwarf_lookup_pc
authorTom de Vries <tdevries@suse.de>
Tue, 12 Feb 2019 14:00:59 +0000 (14:00 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Tue, 12 Feb 2019 14:00:59 +0000 (14:00 +0000)
commit68641fb77c302c75ecc4ab478dc36af00b60215c
tree2dd62060cb986bf7c3b7551130513771d88b2a12
parentb3f2b048eb9833a7d0b72cd1ef68166dcf6bf566
[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.

From-SVN: r268796
libbacktrace/ChangeLog
libbacktrace/dwarf.c