Bug 1354395 - Always bind symbols at load time for ctypes libraries. r?bsmedberg draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 07 Apr 2017 12:07:32 +0900
changeset 560332 925898071b5d9c7acdf91e31108a127ef47741ff
parent 560331 5f2a699a9652f75c1934d319677a4e42c3c82d4b
child 623663 4d69a2673fc250a27d1a06ecff9de21aba115aec
push id53382
push userbmo:mh+mozilla@glandium.org
push dateTue, 11 Apr 2017 08:56:45 +0000
reviewersbsmedberg
bugs1354395
milestone55.0a1
Bug 1354395 - Always bind symbols at load time for ctypes libraries. r?bsmedberg When symbols are not bound at load time, missing symbols can lead to NULL derefs or jumps to 0x0 at runtime, crashing the process running the corresponding JS code, which is rather undesirable. So, prevent libraries that have missing symbols to load at all through ctypes.
js/src/ctypes/Library.cpp
--- a/js/src/ctypes/Library.cpp
+++ b/js/src/ctypes/Library.cpp
@@ -143,17 +143,17 @@ Library::Create(JSContext* cx, HandleVal
                 pathStr->length(), pathBytes, &nbytes));
     pathBytes[nbytes] = 0;
   }
 
   libSpec.value.pathname = pathBytes;
   libSpec.type = PR_LibSpec_Pathname;
 #endif
 
-  PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, 0);
+  PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW);
 
 #ifndef XP_WIN
   JS_free(cx, pathBytes);
 #endif
 
   if (!library) {
 #define MAX_ERROR_LEN 1024
     char error[MAX_ERROR_LEN] = "Cannot get error from NSPR.";