PR26507 UBSAN: elf32-xtensa.c:6013 null pointer bsearch
authorAlan Modra <amodra@gmail.com>
Wed, 26 Aug 2020 10:55:04 +0000 (20:25 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 26 Aug 2020 13:53:45 +0000 (23:23 +0930)
PR 26507
* elf32-xtensa.c (find_removed_literal): Don't bsearch empty map.

bfd/ChangeLog
bfd/elf32-xtensa.c

index 765188d303c2380d7f8362352a1c35bddf4e4e53..988e2f0c649f68e7d4b1ca8784b5d247c1bb1e6b 100644 (file)
@@ -1,3 +1,8 @@
+2020-08-26  Alan Modra  <amodra@gmail.com>
+
+       PR 26507
+       * elf32-xtensa.c (find_removed_literal): Don't bsearch empty map.
+
 2020-08-26  Alan Modra  <amodra@gmail.com>
 
        PR 26506
index 5184fbf1be7646638b157cf5dbe746a25851c113..5824c599ca88bbb47b772c8ee7eb85217f6489f7 100644 (file)
@@ -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;
 }