Bug 1336802 - Part 2: Updating the whole code base to make sure nsILoadInfo get null check. r?smaug draft
authorTim Huang <tihuang@mozilla.com>
Tue, 07 Feb 2017 11:49:34 +0800
changeset 479922 249da8d81c7f94bdec634e3ec0f1f2cc54aca9b3
parent 479733 fe9fd318cf2f4e8ef5473a96ed0459992e1badb3
child 544816 b9ed68d8d03bf473bdd7da82130cfa5f9d3c8035
push id44395
push userbmo:tihuang@mozilla.com
push dateTue, 07 Feb 2017 14:05:15 +0000
reviewerssmaug
bugs1336802
milestone54.0a1
Bug 1336802 - Part 2: Updating the whole code base to make sure nsILoadInfo get null check. r?smaug
dom/base/nsContentUtils.cpp
dom/base/nsObjectLoadingContent.cpp
dom/base/nsScriptLoader.cpp
dom/fetch/FetchDriver.cpp
dom/html/nsHTMLDocument.cpp
dom/security/nsMixedContentBlocker.cpp
dom/workers/ServiceWorkerEvents.cpp
dom/workers/ServiceWorkerPrivate.cpp
dom/xhr/XMLHttpRequestMainThread.cpp
image/imgLoader.cpp
layout/style/Loader.cpp
netwerk/base/Predictor.cpp
netwerk/base/nsNetUtil.cpp
netwerk/protocol/http/InterceptedChannel.cpp
netwerk/protocol/http/nsCORSListenerProxy.cpp
netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
uriloader/prefetch/nsPrefetchService.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9822,16 +9822,19 @@ nsContentUtils::AttemptLargeAllocationLo
   NS_ENSURE_SUCCESS(rv, false);
   NS_ENSURE_TRUE(uri, false);
 
   nsCOMPtr<nsIURI> referrer;
   rv = aChannel->GetReferrer(getter_AddRefs(referrer));
   NS_ENSURE_SUCCESS(rv, false);
 
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+  if (!loadInfo) {
+    return false;
+  }
   nsCOMPtr<nsIPrincipal> triggeringPrincipal = loadInfo->TriggeringPrincipal();
 
   // Get the channel's load flags, and use them to generate nsIWebNavigation
   // load flags. We want to make sure to propagate the refresh and cache busting
   // flags.
   nsLoadFlags channelLoadFlags;
   aChannel->GetLoadFlags(&channelLoadFlags);
 
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -2590,16 +2590,17 @@ nsObjectLoadingContent::OpenChannel()
                      group, // aLoadGroup
                      shim,  // aCallbacks
                      nsIChannel::LOAD_CALL_CONTENT_SNIFFERS |
                      nsIChannel::LOAD_CLASSIFY_URI |
                      nsIChannel::LOAD_BYPASS_SERVICE_WORKER);
   NS_ENSURE_SUCCESS(rv, rv);
   if (inherit) {
     nsCOMPtr<nsILoadInfo> loadinfo = chan->GetLoadInfo();
+    NS_ENSURE_STATE(loadinfo);
     loadinfo->SetPrincipalToInherit(thisContent->NodePrincipal());
   }
 
   // Referrer
   nsCOMPtr<nsIHttpChannel> httpChan(do_QueryInterface(chan));
   if (httpChan) {
     httpChan->SetReferrerWithPolicy(doc->GetDocumentURI(),
                                     doc->GetReferrerPolicy());
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -2495,17 +2495,17 @@ nsScriptLoader::OnStreamComplete(nsIIncr
       mReporter->FlushConsoleReports(mDocument);
     }
     if (NS_FAILED(rv)) {
       rv = NS_ERROR_SRI_CORRUPT;
     }
   } else {
     nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
 
-    if (loadInfo->GetEnforceSRI()) {
+    if (loadInfo && loadInfo->GetEnforceSRI()) {
       MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
               ("nsScriptLoader::OnStreamComplete, required SRI not found"));
       nsCOMPtr<nsIContentSecurityPolicy> csp;
       loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp));
       nsAutoCString violationURISpec;
       mDocument->GetDocumentURI()->GetAsciiSpec(violationURISpec);
       uint32_t lineNo = aRequest->mElement ? aRequest->mElement->GetScriptLineNumber() : 0;
       csp->LogViolationDetails(
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -344,17 +344,19 @@ FetchDriver::HttpFetch()
   // https://fetch.spec.whatwg.org/#cors-preflight-fetch-0. All the
   // implementation is handled by the http channel calling into
   // nsCORSListenerProxy. We just inform it which unsafe headers are included
   // in the request.
   if (mRequest->Mode() == RequestMode::Cors) {
     AutoTArray<nsCString, 5> unsafeHeaders;
     mRequest->Headers()->GetUnsafeHeaders(unsafeHeaders);
     nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
-    loadInfo->SetCorsPreflightInfo(unsafeHeaders, false);
+    if (loadInfo) {
+      loadInfo->SetCorsPreflightInfo(unsafeHeaders, false);
+    }
   }
 
   rv = chan->AsyncOpen2(this);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Step 4 onwards of "HTTP Fetch" is handled internally by Necko.
   return NS_OK;
 }
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -2313,18 +2313,20 @@ nsHTMLDocument::CreateAndAddWyciwygChann
   // Create a wyciwyg Channel
   rv = NS_NewChannel(getter_AddRefs(channel),
                      wcwgURI,
                      NodePrincipal(),
                      nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
                      nsIContentPolicy::TYPE_OTHER);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
+  NS_ENSURE_STATE(loadInfo);
   loadInfo->SetPrincipalToInherit(NodePrincipal());
 
+
   mWyciwygChannel = do_QueryInterface(channel);
 
   mWyciwygChannel->SetSecurityInfo(mSecurityInfo);
 
   // Note: we want to treat this like a "previous document" hint so that,
   // e.g. a <meta> tag in the document.write content can override it.
   SetDocumentCharacterSetSource(kCharsetFromHintPrevDoc);
   mWyciwygChannel->SetCharsetAndSource(kCharsetFromHintPrevDoc,
--- a/dom/security/nsMixedContentBlocker.cpp
+++ b/dom/security/nsMixedContentBlocker.cpp
@@ -370,22 +370,26 @@ nsMixedContentBlocker::AsyncOnChannelRed
 
   if (nsMixedContentBlocker::sSendHSTSPriming) {
     // The LoadInfo passed in is for the original channel, HSTS priming needs to
     // be set on the new channel, if required. If the redirect changes
     // http->https, or vice-versa, the need for priming may change.
     nsCOMPtr<nsILoadInfo> newLoadInfo;
     rv = aNewChannel->GetLoadInfo(getter_AddRefs(newLoadInfo));
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = nsMixedContentBlocker::MarkLoadInfoForPriming(newUri,
-                                                       requestingContext,
-                                                       newLoadInfo);
-    if (NS_FAILED(rv)) {
+    if (newLoadInfo) {
+      rv = nsMixedContentBlocker::MarkLoadInfoForPriming(newUri,
+                                                         requestingContext,
+                                                         newLoadInfo);
+      if (NS_FAILED(rv)) {
+        decision = REJECT_REQUEST;
+        newLoadInfo->ClearHSTSPriming();
+      }
+    } else {
       decision = REJECT_REQUEST;
-      newLoadInfo->ClearHSTSPriming();
     }
   }
 
   // If the channel is about to load mixed content, abort the channel
   if (!NS_CP_ACCEPTED(decision)) {
     autoCallback.DontCallback();
     return NS_BINDING_FAILED;
   }
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -185,17 +185,17 @@ public:
     AssertIsOnMainThread();
 
     nsCOMPtr<nsIChannel> underlyingChannel;
     nsresult rv = mChannel->GetChannel(getter_AddRefs(underlyingChannel));
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(underlyingChannel, NS_ERROR_UNEXPECTED);
     nsCOMPtr<nsILoadInfo> loadInfo = underlyingChannel->GetLoadInfo();
 
-    if (!CSPPermitsResponse(loadInfo)) {
+    if (!loadInfo || !CSPPermitsResponse(loadInfo)) {
       mChannel->Cancel(NS_ERROR_CONTENT_BLOCKED);
       return NS_OK;
     }
 
     ChannelInfo channelInfo;
     if (mInternalResponse->GetChannelInfo().IsInitialized()) {
       channelInfo = mInternalResponse->GetChannelInfo();
     } else {
--- a/dom/workers/ServiceWorkerPrivate.cpp
+++ b/dom/workers/ServiceWorkerPrivate.cpp
@@ -1370,18 +1370,20 @@ public:
     NS_ENSURE_SUCCESS(rv, rv);
 
     uint32_t loadFlags;
     rv = channel->GetLoadFlags(&loadFlags);
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<nsILoadInfo> loadInfo;
     rv = channel->GetLoadInfo(getter_AddRefs(loadInfo));
     NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_STATE(loadInfo);
     mContentPolicyType = loadInfo->InternalContentPolicyType();
 
+
     nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
     MOZ_ASSERT(httpChannel, "How come we don't have an HTTP channel?");
 
     nsAutoCString referrer;
     // Ignore the return value since the Referer header may not exist.
     httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("Referer"), referrer);
     if (!referrer.IsEmpty()) {
       mReferrer = referrer;
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -870,16 +870,20 @@ XMLHttpRequestMainThread::IsCrossSiteCOR
 {
   if (!mChannel) {
     return false;
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
   MOZ_ASSERT(loadInfo);
 
+  if (!loadInfo) {
+    return false;
+  }
+
   return loadInfo->GetTainting() == LoadTainting::CORS;
 }
 
 bool
 XMLHttpRequestMainThread::IsDeniedCrossSiteCORSRequest()
 {
   if (IsCrossSiteCORSRequest()) {
     nsresult rv;
@@ -1611,17 +1615,19 @@ void
 XMLHttpRequestMainThread::SetOriginAttributes(const OriginAttributesDictionary& aAttrs)
 {
   MOZ_ASSERT((mState == State::opened) && !mFlagSend);
 
   OriginAttributes attrs(aAttrs);
 
   nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
   MOZ_ASSERT(loadInfo);
-  loadInfo->SetOriginAttributes(attrs);
+  if (loadInfo) {
+    loadInfo->SetOriginAttributes(attrs);
+  }
 }
 
 void
 XMLHttpRequestMainThread::PopulateNetworkInterfaceId()
 {
   if (mNetworkInterfaceId.IsEmpty()) {
     return;
   }
@@ -2020,17 +2026,20 @@ XMLHttpRequestMainThread::OnStartRequest
     }
 
     if (nsContentUtils::IsSystemPrincipal(mPrincipal)) {
       mResponseXML->ForceEnableXULXBL();
     }
 
     nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
     MOZ_ASSERT(loadInfo);
-    bool isCrossSite = loadInfo->GetTainting() != LoadTainting::Basic;
+    bool isCrossSite = false;
+    if (loadInfo) {
+      isCrossSite = loadInfo->GetTainting() != LoadTainting::Basic;
+    }
 
     if (isCrossSite) {
       nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mResponseXML);
       if (htmlDoc) {
         htmlDoc->DisableCookieAccess();
       }
     }
 
@@ -2392,18 +2401,20 @@ XMLHttpRequestMainThread::CreateChannel(
       if (NS_SUCCEEDED(principal->CheckMayLoad(mRequestURL, false, dataInherits))) {
         resultingDocumentPrincipal = principal;
         break;
       }
     }
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-  rv = loadInfo->SetPrincipalToInherit(resultingDocumentPrincipal);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (loadInfo) {
+    rv = loadInfo->SetPrincipalToInherit(resultingDocumentPrincipal);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   return NS_OK;
 }
 
 nsresult
 XMLHttpRequestMainThread::InitiateFetch(nsIInputStream* aUploadStream,
                                         int64_t aUploadLength,
                                         nsACString& aUploadContentType)
@@ -2498,17 +2509,19 @@ XMLHttpRequestMainThread::InitiateFetch(
   }
 
   // Due to the chrome-only XHR.channel API, we need a hacky way to set the
   // SEC_COOKIES_INCLUDE *after* the channel has been has been created, since
   // .withCredentials can be called after open() is called.
   // Not doing this for privileged system XHRs since those don't use CORS.
   if (!IsSystemXHR() && !mIsAnon && mFlagACwithCredentials) {
     nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    static_cast<net::LoadInfo*>(loadInfo.get())->SetIncludeCookiesSecFlag();
+    if (loadInfo) {
+      static_cast<net::LoadInfo*>(loadInfo.get())->SetIncludeCookiesSecFlag();
+    }
   }
 
   // Blocking gets are common enough out of XHR that we should mark
   // the channel slow by default for pipeline purposes
   AddLoadFlags(mChannel, nsIRequest::INHIBIT_PIPELINE);
 
   // We never let XHR be blocked by head CSS/JS loads to avoid potential
   // deadlock where server generation of CSS/JS requires an XHR signal.
@@ -2559,18 +2572,20 @@ XMLHttpRequestMainThread::InitiateFetch(
     mChannel->SetContentType(NS_LITERAL_CSTRING("application/xml"));
   }
 
   // Set up the preflight if needed
   if (!IsSystemXHR()) {
     nsTArray<nsCString> CORSUnsafeHeaders;
     mAuthorRequestHeaders.GetCORSUnsafeHeaders(CORSUnsafeHeaders);
     nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
-    loadInfo->SetCorsPreflightInfo(CORSUnsafeHeaders,
-                                   mFlagHadUploadListenersOnSend);
+    if (loadInfo) {
+      loadInfo->SetCorsPreflightInfo(CORSUnsafeHeaders,
+                                     mFlagHadUploadListenersOnSend);
+    }
   }
 
   // Hook us up to listen to redirects and the like. Only do this very late
   // since this creates a cycle between the channel and us. This cycle has
   // to be manually broken if anything below fails.
   mChannel->GetNotificationCallbacks(getter_AddRefs(mNotificationCallbacks));
   mChannel->SetNotificationCallbacks(this);
 
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -751,17 +751,19 @@ NewImageChannel(nsIChannel** aResult,
     if (aPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) {
       // If this is a favicon loading, we will use the originAttributes from the
       // loadingPrincipal as the channel's originAttributes. This allows the favicon
       // loading from XUL will use the correct originAttributes.
       OriginAttributes attrs;
       attrs.Inherit(aLoadingPrincipal->OriginAttributesRef());
 
       nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
-      rv = loadInfo->SetOriginAttributes(attrs);
+      if (loadInfo) {
+        rv = loadInfo->SetOriginAttributes(attrs);
+      }
     }
   } else {
     // either we are loading something inside a document, in which case
     // we should always have a requestingNode, or we are loading something
     // outside a document, in which case the loadingPrincipal and
     // triggeringPrincipal should always be the systemPrincipal.
     // However, there are exceptions: one is Notifications which create a
     // channel in the parent prcoess in which case we can't get a requestingNode.
@@ -783,17 +785,19 @@ NewImageChannel(nsIChannel** aResult,
     // has asked us to perform.
     OriginAttributes attrs;
     if (aLoadingPrincipal) {
       attrs.Inherit(aLoadingPrincipal->OriginAttributesRef());
     }
     attrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0;
 
     nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
-    rv = loadInfo->SetOriginAttributes(attrs);
+    if (loadInfo) {
+      rv = loadInfo->SetOriginAttributes(attrs);
+    }
   }
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // only inherit if we have a principal
   *aForcePrincipalCheckForCacheEntry =
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -937,17 +937,17 @@ SheetLoadData::OnStreamComplete(nsIUnich
       return NS_OK;
     }
   }
 
   SRIMetadata sriMetadata;
   mSheet->GetIntegrity(sriMetadata);
   if (sriMetadata.IsEmpty()) {
     nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-    if (loadInfo->GetEnforceSRI()) {
+    if (loadInfo && loadInfo->GetEnforceSRI()) {
       LOG(("  Load was blocked by SRI"));
       MOZ_LOG(gSriPRLog, mozilla::LogLevel::Debug,
               ("css::Loader::OnStreamComplete, required SRI not found"));
       mLoader->SheetComplete(this, NS_ERROR_SRI_CORRUPT);
       // log the failed load to web console
       nsCOMPtr<nsIContentSecurityPolicy> csp;
       loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp));
       nsAutoCString spec;
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -1347,17 +1347,19 @@ Predictor::Prefetch(nsIURI *uri, nsIURI 
                               nsIRequest::LOAD_BACKGROUND);
 
   if (NS_FAILED(rv)) {
     PREDICTOR_LOG(("    NS_NewChannel failed rv=0x%X", rv));
     return rv;
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
-  rv = loadInfo->SetOriginAttributes(originAttributes);
+  if (loadInfo) {
+    rv = loadInfo->SetOriginAttributes(originAttributes);
+  }
 
   if (NS_FAILED(rv)) {
     PREDICTOR_LOG(("    Set originAttributes into loadInfo failed rv=0x%X", rv));
     return rv;
   }
 
   nsCOMPtr<nsIHttpChannel> httpChannel;
   httpChannel = do_QueryInterface(channel);
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1262,16 +1262,20 @@ NS_GetOriginAttributes(nsIChannel *aChan
 }
 
 bool
 NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport)
 {
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
   MOZ_RELEASE_ASSERT(loadInfo, "Origin tracking only works for channels created with a loadinfo");
 
+  if (!loadInfo) {
+    return false;
+  }
+
   // TYPE_DOCUMENT loads have a null LoadingPrincipal and can not be cross origin.
   if (!loadInfo->LoadingPrincipal()) {
     return false;
   }
 
   // Always treat tainted channels as cross-origin.
   if (loadInfo->GetTainting() != LoadTainting::Basic) {
     return true;
--- a/netwerk/protocol/http/InterceptedChannel.cpp
+++ b/netwerk/protocol/http/InterceptedChannel.cpp
@@ -341,18 +341,19 @@ InterceptedChannelChrome::SetChannelInfo
 
 NS_IMETHODIMP
 InterceptedChannelChrome::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType)
 {
   NS_ENSURE_ARG(aPolicyType);
   nsCOMPtr<nsILoadInfo> loadInfo;
   nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
   NS_ENSURE_SUCCESS(rv, rv);
-
-  *aPolicyType = loadInfo->InternalContentPolicyType();
+  if (loadInfo) {
+    *aPolicyType = loadInfo->InternalContentPolicyType();
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedChannelChrome::GetSecureUpgradedChannelURI(nsIURI** aURI)
 {
   return mChannel->GetURI(aURI);
 }
@@ -510,17 +511,19 @@ NS_IMETHODIMP
 InterceptedChannelContent::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType)
 {
   NS_ENSURE_ARG(aPolicyType);
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  *aPolicyType = loadInfo->InternalContentPolicyType();
+  if (loadInfo) {
+    *aPolicyType = loadInfo->InternalContentPolicyType();
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedChannelContent::GetSecureUpgradedChannelURI(nsIURI** aURI)
 {
   nsCOMPtr<nsIURI> uri;
   if (mSecureUpgrade) {
--- a/netwerk/protocol/http/nsCORSListenerProxy.cpp
+++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp
@@ -862,16 +862,20 @@ CheckUpgradeInsecureRequestsPreventsCORS
   if (!channelHost.EqualsIgnoreCase(origChannelHost.get())) {
     return false;
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   rv = aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
   NS_ENSURE_SUCCESS(rv, false);
 
+  if (!loadInfo) {
+    return false;
+  }
+
   // lets see if the loadInfo indicates that the request will
   // be upgraded before fetching any data from the netwerk.
   return loadInfo->GetUpgradeInsecureRequests();
 }
 
 
 nsresult
 nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel,
--- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
@@ -122,17 +122,19 @@ WyciwygChannelParent::RecvInit(const URI
   if (NS_FAILED(rv)) {
     if (!SendCancelEarly(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
     return IPC_OK();
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo = chan->GetLoadInfo();
-  rv = loadInfo->SetPrincipalToInherit(principalToInherit);
+  if (loadInfo) {
+    rv = loadInfo->SetPrincipalToInherit(principalToInherit);
+  }
   if (NS_FAILED(rv)) {
     if (!SendCancelEarly(rv)) {
       return IPC_FAIL_NO_REASON(this);
     }
     return IPC_OK();
   }
 
   mChannel = do_QueryInterface(chan, &rv);
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -128,17 +128,19 @@ nsUrlClassifierStreamUpdater::FetchUpdat
                      this,     // aInterfaceRequestor
                      loadFlags);
 
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
   mozilla::OriginAttributes attrs;
   attrs.mFirstPartyDomain.AssignLiteral(NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN);
-  loadInfo->SetOriginAttributes(attrs);
+  if (loadInfo) {
+    loadInfo->SetOriginAttributes(attrs);
+  }
 
   mBeganStream = false;
 
   if (!aIsPostRequest) {
     // We use POST method to send our request in v2. In v4, the request
     // needs to be embedded to the URL and use GET method to send.
     // However, from the Chromium source code, a extended HTTP header has
     // to be sent along with the request to make the request succeed.
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -197,20 +197,22 @@ nsPrefetchNode::OnStartRequest(nsIReques
 
     nsCOMPtr<nsIHttpChannel> httpChannel =
         do_QueryInterface(aRequest, &rv);
     if (NS_FAILED(rv)) return rv;
 
     // if the load is cross origin without CORS, or the CORS access is rejected,
     // always fire load event to avoid leaking site information.
     nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->GetLoadInfo();
-    mShouldFireLoadEvent = loadInfo->GetTainting() == LoadTainting::Opaque ||
-                           (loadInfo->GetTainting() == LoadTainting::CORS &&
-                            (NS_FAILED(httpChannel->GetStatus(&rv)) ||
-                             NS_FAILED(rv)));
+    if (loadInfo) {
+        mShouldFireLoadEvent = loadInfo->GetTainting() == LoadTainting::Opaque ||
+                               (loadInfo->GetTainting() == LoadTainting::CORS &&
+                                (NS_FAILED(httpChannel->GetStatus(&rv)) ||
+                                 NS_FAILED(rv)));
+    }
 
     // no need to prefetch http error page
     bool requestSucceeded;
     if (NS_FAILED(httpChannel->GetRequestSucceeded(&requestSucceeded)) ||
         !requestSucceeded) {
       return NS_BINDING_ABORTED;
     }