From 4d43072582c3ccbb86485d79107a9d3550a1557a Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 26 Aug 2020 20:25:04 +0930 Subject: [PATCH] PR26507 UBSAN: elf32-xtensa.c:6013 null pointer bsearch PR 26507 * elf32-xtensa.c (find_removed_literal): Don't bsearch empty map. --- bfd/ChangeLog | 5 +++++ bfd/elf32-xtensa.c | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 765188d303c..988e2f0c649 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2020-08-26 Alan Modra + + PR 26507 + * elf32-xtensa.c (find_removed_literal): Don't bsearch empty map. + 2020-08-26 Alan Modra PR 26506 diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 5184fbf1be7..5824c599ca8 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -6014,13 +6014,16 @@ find_removed_literal (removed_literal_list *removed_list, bfd_vma addr) if (removed_list->map == NULL) map_removed_literal (removed_list); - p = bsearch (&addr, removed_list->map, removed_list->n_map, - sizeof (*removed_list->map), removed_literal_compare); - if (p) + if (removed_list->map != NULL) { - while (p != removed_list->map && (p - 1)->addr == addr) - --p; - r = p->literal; + p = bsearch (&addr, removed_list->map, removed_list->n_map, + sizeof (*removed_list->map), removed_literal_compare); + if (p) + { + while (p != removed_list->map && (p - 1)->addr == addr) + --p; + r = p->literal; + } } return r; } -- 2.30.2