Bug 1517434 part 3. Get rid of pointer compares to nsXPConnect::SystemPrincipal. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 03 Jan 2019 21:08:15 +0000
changeset 509578 1853f95c94b101e7e24a180f6eacaf2a628e5863
parent 509577 840ea11d3b3efb306c862c9984e089f226f3bfc4
child 509579 a18c59a93e0583f45d8367eaa11ca5fc4f842397
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1517434
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 1517434 part 3. Get rid of pointer compares to nsXPConnect::SystemPrincipal. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D15674
js/xpconnect/src/Sandbox.cpp
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -59,16 +59,17 @@
 #include "mozilla/dom/TextDecoderBinding.h"
 #include "mozilla/dom/TextEncoderBinding.h"
 #include "mozilla/dom/UnionConversions.h"
 #include "mozilla/dom/URLBinding.h"
 #include "mozilla/dom/URLSearchParamsBinding.h"
 #include "mozilla/dom/XMLHttpRequest.h"
 #include "mozilla/dom/XMLSerializerBinding.h"
 #include "mozilla/dom/FormDataBinding.h"
+#include "mozilla/BasePrincipal.h"
 #include "mozilla/DeferredFinalize.h"
 #include "mozilla/NullPrincipal.h"
 
 using namespace mozilla;
 using namespace JS;
 using namespace xpc;
 
 using mozilla::dom::DestroyProtoAndIfaceCache;
@@ -1040,17 +1041,17 @@ nsresult xpc::CreateSandboxObject(JSCont
   JS::RealmOptions realmOptions;
 
   auto& creationOptions = realmOptions.creationOptions();
 
   // XXXjwatt: Consider whether/when sandboxes should be able to see
   // [SecureContext] API (bug 1273687).  In that case we'd call
   // creationOptions.setSecureContext(true).
 
-  bool isSystemPrincipal = principal == nsXPConnect::SystemPrincipal();
+  bool isSystemPrincipal = principal->IsSystemPrincipal();
   if (isSystemPrincipal) {
     creationOptions.setClampAndJitterTime(false);
   }
 
   xpc::SetPrefableRealmOptions(realmOptions);
   if (options.sameZoneAs) {
     creationOptions.setNewCompartmentInExistingZone(
         js::UncheckedUnwrap(options.sameZoneAs));
@@ -1166,17 +1167,17 @@ nsresult xpc::CreateSandboxObject(JSCont
       }
 
       ok = JS_SplicePrototype(cx, sandbox, options.proto);
       if (!ok) {
         return NS_ERROR_XPC_UNEXPECTED;
       }
     }
 
-    bool allowComponents = principal == nsXPConnect::SystemPrincipal();
+    bool allowComponents = principal->IsSystemPrincipal();
     if (options.wantComponents && allowComponents &&
         !ObjectScope(sandbox)->AttachComponentsObject(cx))
       return NS_ERROR_XPC_UNEXPECTED;
 
     if (!XPCNativeWrapper::AttachNewConstructorObject(cx, sandbox)) {
       return NS_ERROR_XPC_UNEXPECTED;
     }
 
@@ -1343,17 +1344,16 @@ static bool GetExpandedPrincipal(JSConte
 
   // First pass:
   for (uint32_t i = 0; i < length; ++i) {
     RootedValue allowed(cx);
     if (!JS_GetElement(cx, arrayObj, i, &allowed)) {
       return false;
     }
 
-    nsresult rv;
     nsCOMPtr<nsIPrincipal> principal;
     if (allowed.isObject()) {
       // In case of object let's see if it's a Principal or a
       // ScriptObjectPrincipal.
       nsCOMPtr<nsISupports> prinOrSop;
       RootedObject obj(cx, &allowed.toObject());
       if (!GetPrincipalOrSOP(cx, obj, getter_AddRefs(prinOrSop))) {
         return false;
@@ -1376,20 +1376,17 @@ static bool GetExpandedPrincipal(JSConte
           // principal we have here.
           // If attrs comes from OriginAttributes, we don't need
           // this check.
           return false;
         }
       }
 
       // We do not allow ExpandedPrincipals to contain any system principals.
-      bool isSystem;
-      rv = nsXPConnect::SecurityManager()->IsSystemPrincipal(principal,
-                                                             &isSystem);
-      NS_ENSURE_SUCCESS(rv, false);
+      bool isSystem = principal->IsSystemPrincipal();
       if (isSystem) {
         JS_ReportErrorASCII(
             cx, "System principal is not allowed in an expanded principal");
         return false;
       }
       allowedDomains[i] = principal;
     } else if (allowed.isString()) {
       // Skip any string arguments - we handle them in the next pass.