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 560334 689a1c152a5ba50c2c68f7d9d8a65eaff2eabe8c
parent 560333 edb8934ad24399d2f08320fa99551d878f2e809e
child 623664 58ceec62e4e98aa997635459a08fcf5e6f05b71c
push id53383
push userbmo:mh+mozilla@glandium.org
push dateTue, 11 Apr 2017 08:57:31 +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.";