diff options
author | Tom de Vries <tdevries@suse.de> | 2019-02-12 14:00:59 +0000 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2019-02-12 14:00:59 +0000 |
commit | 32f41cec36439250f0d64c466e301dc7399565f3 (patch) | |
tree | 2dd62060cb986bf7c3b7551130513771d88b2a12 /libbacktrace | |
parent | 5dcee13f632492234822fd50a1625a84ff251cab (diff) |
[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.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@268796 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libbacktrace')
-rw-r--r-- | libbacktrace/ChangeLog | 5 | ||||
-rw-r--r-- | libbacktrace/dwarf.c | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 9e0da6353e3..e29c41f78ed 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,8 @@ +2019-02-12 Tom de Vries <tdevries@suse.de> + + PR libbacktrace/81983 + * dwarf.c (dwarf_lookup_pc): Don't call bsearch if nmemb == 0. + 2019-02-10 Tom de Vries <tdevries@suse.de> * Makefile.am (BUILDTESTS): Add btest_lto. diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c index d7dacf3ef32..f338489fe44 100644 --- a/libbacktrace/dwarf.c +++ b/libbacktrace/dwarf.c @@ -2821,8 +2821,10 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata, *found = 1; /* Find an address range that includes PC. */ - entry = bsearch (&pc, ddata->addrs, ddata->addrs_count, - sizeof (struct unit_addrs), unit_addrs_search); + entry = (ddata->addrs_count == 0 + ? NULL + : bsearch (&pc, ddata->addrs, ddata->addrs_count, + sizeof (struct unit_addrs), unit_addrs_search)); if (entry == NULL) { |