Bug 1295103 - Check OriginAttributes::PopulateFromSuffix return value in TabContext and ContentChild. r=smaug draft
authorKan-Ru Chen <kanru@kanru.info>
Mon, 15 Aug 2016 18:21:53 +0800
changeset 404365 d7897a47bb5dc1c588bbbd6c57e8edce158690f2
parent 404364 573eea59bf2efae6109c74b230dc3dc5b825ed70
child 404366 fafb3e005c6869a1c9943b89ffc7fce60397a3be
push id27198
push userbmo:kchen@mozilla.com
push dateTue, 23 Aug 2016 10:29:41 +0000
reviewerssmaug
bugs1295103
milestone51.0a1
Bug 1295103 - Check OriginAttributes::PopulateFromSuffix return value in TabContext and ContentChild. r=smaug MozReview-Commit-ID: JWtO5rqJGBF
dom/ipc/ContentChild.cpp
dom/ipc/TabContext.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -2431,17 +2431,18 @@ ContentChild::RecvAddPermission(const IP
     static_cast<nsPermissionManager*>(permissionManagerIface.get());
   MOZ_ASSERT(permissionManager,
          "We have no permissionManager in the Content process !");
 
   // note we do not need to force mUserContextId to the default here because
   // the permission manager does that internally.
   nsAutoCString originNoSuffix;
   PrincipalOriginAttributes attrs;
-  attrs.PopulateFromOrigin(permission.origin, originNoSuffix);
+  bool success = attrs.PopulateFromOrigin(permission.origin, originNoSuffix);
+  NS_ENSURE_TRUE(success, false);
 
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_NewURI(getter_AddRefs(uri), originNoSuffix);
   NS_ENSURE_SUCCESS(rv, true);
 
   nsCOMPtr<nsIPrincipal> principal = mozilla::BasePrincipal::CreateCodebasePrincipal(uri, attrs);
 
   // child processes don't care about modification time.
--- a/dom/ipc/TabContext.cpp
+++ b/dom/ipc/TabContext.cpp
@@ -364,17 +364,20 @@ MaybeInvalidTabContext::MaybeInvalidTabC
       isMozBrowserElement = ipcContext.isMozBrowserElement();
       isPrerendered = ipcContext.isPrerendered();
       containingAppId = ipcContext.frameOwnerAppId();
       signedPkgOriginNoSuffix = ipcContext.signedPkgOriginNoSuffix();
       presentationURL = ipcContext.presentationURL();
       showAccelerators = ipcContext.showAccelerators();
       showFocusRings = ipcContext.showFocusRings();
       originSuffix = ipcContext.originSuffix();
-      originAttributes.PopulateFromSuffix(originSuffix);
+      if (!originAttributes.PopulateFromSuffix(originSuffix)) {
+        mInvalidReason = "Populate originAttributes from originSuffix failed.";
+        return;
+      }
       break;
     }
     case IPCTabContext::TUnsafeIPCTabContext: {
       // XXXcatalinb: This used *only* by ServiceWorkerClients::OpenWindow.
       // It is meant as a temporary solution until service workers can
       // provide a TabChild equivalent. Don't allow this on b2g since
       // it might be used to escalate privileges.
 #ifdef MOZ_B2G