Bug 1472676: Fix NULL_DEREFERENCE errors draft
authorRobert Bartlensky <rbartlensky@mozilla.com>
Wed, 04 Jul 2018 15:20:59 +0100
changeset 814117 c8e1824b0e2e3db71581d214404ec7c159fb3e89
parent 814073 a9dc5dc8e2b8513686ad1b1f28c9e4da6de62226
child 814128 dc50f0665660956785851df6ed998f6ca209a262
push id115104
push userbmo:rbartlensky@mozilla.com
push dateWed, 04 Jul 2018 14:22:32 +0000
bugs1472676
milestone63.0a1
Bug 1472676: Fix NULL_DEREFERENCE errors MozReview-Commit-ID: B5urPwsgGto
dom/ipc/ContentChild.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -768,19 +768,24 @@ ContentChild::ProvideWindow(mozIDOMWindo
 static nsresult
 GetCreateWindowParams(mozIDOMWindowProxy* aParent,
                       nsIDocShellLoadInfo* aLoadInfo,
                       nsACString& aBaseURIString, float* aFullZoom,
                       uint32_t* aReferrerPolicy,
                       nsIPrincipal** aTriggeringPrincipal)
 {
   *aFullZoom = 1.0f;
+  if (!aTriggeringPrincipal) {
+    NS_ERROR("aTriggeringPrincipal is null");
+    return NS_ERROR_FAILURE;
+  }
   auto* opener = nsPIDOMWindowOuter::From(aParent);
   if (!opener) {
-    nsCOMPtr<nsIPrincipal> nullPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
+    nsCOMPtr<nsIPrincipal> nullPrincipal =
+      NullPrincipal::CreateWithoutOriginAttributes();
     NS_ADDREF(*aTriggeringPrincipal = nullPrincipal);
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> doc = opener->GetDoc();
   NS_ADDREF(*aTriggeringPrincipal = doc->NodePrincipal());
   nsCOMPtr<nsIURI> baseURI = doc->GetDocBaseURI();
   if (!baseURI) {
@@ -2256,27 +2261,31 @@ ContentChild::RecvRegisterChrome(Infalli
                                  InfallibleTArray<SubstitutionMapping>&& resources,
                                  InfallibleTArray<OverrideMapping>&& overrides,
                                  const nsCString& locale,
                                  const bool& reset)
 {
   nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
   nsChromeRegistryContent* chromeRegistry =
     static_cast<nsChromeRegistryContent*>(registrySvc.get());
+  if (!chromeRegistry)
+    return IPC_FAIL(this, "ChromeRegistryContent is null!");
   chromeRegistry->RegisterRemoteChrome(packages, resources, overrides,
                                        locale, reset);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 ContentChild::RecvRegisterChromeItem(const ChromeRegistryItem& item)
 {
   nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
   nsChromeRegistryContent* chromeRegistry =
     static_cast<nsChromeRegistryContent*>(registrySvc.get());
+  if (!chromeRegistry)
+    return IPC_FAIL(this, "ChromeRegistryContent is null!");
   switch (item.type()) {
     case ChromeRegistryItem::TChromePackage:
       chromeRegistry->RegisterPackage(item.get_ChromePackage());
       break;
 
     case ChromeRegistryItem::TOverrideMapping:
       chromeRegistry->RegisterOverride(item.get_OverrideMapping());
       break;