[binutils-gdb] PR26431 UBSAN: pe-dll.c:568 null pointer bsearch

Alan Modra amodra@sourceware.org
Wed Aug 26 13:54:36 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=aaf9875ef9252ec42bafac076421cc5ff22965ad

commit aaf9875ef9252ec42bafac076421cc5ff22965ad
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Aug 26 14:23:42 2020 +0930

    PR26431 UBSAN: pe-dll.c:568 null pointer bsearch
    
            PR 26431
            * pe-dll.c (auto_export): Don't call bsearch with zero count.

Diff:
---
 ld/ChangeLog | 5 +++++
 ld/pe-dll.c  | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index a12f91302b7..882e1c920e3 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-26  Alan Modra  <amodra@gmail.com>
+
+	PR 26431
+	* pe-dll.c (auto_export): Don't call bsearch with zero count.
+
 2020-08-25  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-libs/libs.exp: Don't run on sh-pe, tic30 or tic54x.
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 3e8fe1be9b3..39c8e4c5ea7 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -565,8 +565,9 @@ auto_export (bfd *abfd, def_file *d, const char *n)
   key.name = key.its_name = (char *) n;
 
   /* Return false if n is in the d->exports table.  */
-  if (bsearch (&key, d->exports, d->num_exports,
-	       sizeof (pe_def_file->exports[0]), pe_export_sort))
+  if (d->num_exports != 0
+      && bsearch (&key, d->exports, d->num_exports,
+		  sizeof (pe_def_file->exports[0]), pe_export_sort))
     return 0;
 
   if (pe_dll_do_default_excludes)


More information about the Binutils-cvs mailing list