Bug 1513277 part 1 - Use the scripted caller's global in Cu.importGlobalProperties. r=kmag
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 12 Dec 2018 21:03:18 +0000
changeset 450360 63993693c624ce68ae3e11d0e92b98fb86e431b6
parent 450358 a7266f39e1df0cfffbef96a5a8cf85aa004c86cb
child 450361 c38131baf66082a231aa7ce376b12ff886516ab7
push id110479
push usercsabou@mozilla.com
push dateThu, 13 Dec 2018 04:02:11 +0000
treeherdermozilla-inbound@3ecc407c0cc8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1513277
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513277 part 1 - Use the scripted caller's global in Cu.importGlobalProperties. r=kmag With same-compartment-realms enabled we can call a cross-realm Cu.importGlobalProperties and we ended up defining properties on the wrong global. Differential Revision: https://phabricator.services.mozilla.com/D14179
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1584,18 +1584,23 @@ nsXPCComponents_Utils::Unload(const nsAC
   RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
   MOZ_ASSERT(moduleloader);
   return moduleloader->Unload(registryLocation);
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::ImportGlobalProperties(HandleValue aPropertyList,
                                               JSContext* cx) {
-  RootedObject global(cx, CurrentGlobalOrNull(cx));
+  // Ensure we're working in the scripted caller's realm. This is not guaranteed
+  // to be the current realm because we switch realms when calling cross-realm
+  // functions.
+  RootedObject global(cx, JS::GetScriptedCallerGlobal(cx));
   MOZ_ASSERT(global);
+  js::AssertSameCompartment(cx, global);
+  JSAutoRealm ar(cx, global);
 
   // Don't allow doing this if the global is a Window
   nsGlobalWindowInner* win;
   if (NS_SUCCEEDED(UNWRAP_OBJECT(Window, &global, win))) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   GlobalProperties options;