diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 5550e71eefc04..f038233228ec1 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -9831,6 +9831,9 @@ nsContentUtils::AttemptLargeAllocationLoad(nsIHttpChannel* aChannel) NS_ENSURE_SUCCESS(rv, false); nsCOMPtr loadInfo = aChannel->GetLoadInfo(); + if (!loadInfo) { + return false; + } nsCOMPtr triggeringPrincipal = loadInfo->TriggeringPrincipal(); // Get the channel's load flags, and use them to generate nsIWebNavigation diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 05770d8ce4efc..59752ffbf2e0e 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -2595,6 +2595,7 @@ nsObjectLoadingContent::OpenChannel() NS_ENSURE_SUCCESS(rv, rv); if (inherit) { nsCOMPtr loadinfo = chan->GetLoadInfo(); + NS_ENSURE_STATE(loadinfo); loadinfo->SetPrincipalToInherit(thisContent->NodePrincipal()); } diff --git a/dom/base/nsScriptLoader.cpp b/dom/base/nsScriptLoader.cpp index e6f4bf56e89b0..6ef02f59a3c8a 100644 --- a/dom/base/nsScriptLoader.cpp +++ b/dom/base/nsScriptLoader.cpp @@ -2524,7 +2524,7 @@ nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, } else { nsCOMPtr loadInfo = channel->GetLoadInfo(); - if (loadInfo->GetEnforceSRI()) { + if (loadInfo && loadInfo->GetEnforceSRI()) { MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug, ("nsScriptLoader::OnStreamComplete, required SRI not found")); nsCOMPtr csp; diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index 1350a25d35a9a..7ee425451c642 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -349,7 +349,9 @@ FetchDriver::HttpFetch() AutoTArray unsafeHeaders; mRequest->Headers()->GetUnsafeHeaders(unsafeHeaders); nsCOMPtr loadInfo = chan->GetLoadInfo(); - loadInfo->SetCorsPreflightInfo(unsafeHeaders, false); + if (loadInfo) { + loadInfo->SetCorsPreflightInfo(unsafeHeaders, false); + } } rv = chan->AsyncOpen2(this); diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 0de86dbd3e6d8..1c441fef194b7 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -2318,8 +2318,10 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void) nsIContentPolicy::TYPE_OTHER); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr loadInfo = channel->GetLoadInfo(); + NS_ENSURE_STATE(loadInfo); loadInfo->SetPrincipalToInherit(NodePrincipal()); + mWyciwygChannel = do_QueryInterface(channel); mWyciwygChannel->SetSecurityInfo(mSecurityInfo); diff --git a/dom/security/nsMixedContentBlocker.cpp b/dom/security/nsMixedContentBlocker.cpp index a467e9bab1d35..4c319bcf75913 100644 --- a/dom/security/nsMixedContentBlocker.cpp +++ b/dom/security/nsMixedContentBlocker.cpp @@ -375,12 +375,16 @@ nsMixedContentBlocker::AsyncOnChannelRedirect(nsIChannel* aOldChannel, nsCOMPtr 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(); } } diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 9106100edcf59..54027c759a2e5 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -190,7 +190,7 @@ class FinishResponse final : public Runnable NS_ENSURE_TRUE(underlyingChannel, NS_ERROR_UNEXPECTED); nsCOMPtr loadInfo = underlyingChannel->GetLoadInfo(); - if (!CSPPermitsResponse(loadInfo)) { + if (!loadInfo || !CSPPermitsResponse(loadInfo)) { mChannel->Cancel(NS_ERROR_CONTENT_BLOCKED); return NS_OK; } diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index e9f0cf7df727c..9d2d6ec5155e8 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -1375,8 +1375,10 @@ class FetchEventRunnable : public ExtendableFunctionalEventWorkerRunnable nsCOMPtr loadInfo; rv = channel->GetLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_STATE(loadInfo); mContentPolicyType = loadInfo->InternalContentPolicyType(); + nsCOMPtr httpChannel = do_QueryInterface(channel); MOZ_ASSERT(httpChannel, "How come we don't have an HTTP channel?"); diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 9c790e16d5d71..cf0a6c498feb7 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -867,6 +867,10 @@ XMLHttpRequestMainThread::IsCrossSiteCORSRequest() const nsCOMPtr loadInfo = mChannel->GetLoadInfo(); MOZ_ASSERT(loadInfo); + if (!loadInfo) { + return false; + } + return loadInfo->GetTainting() == LoadTainting::CORS; } @@ -1608,7 +1612,9 @@ XMLHttpRequestMainThread::SetOriginAttributes(const OriginAttributesDictionary& nsCOMPtr loadInfo = mChannel->GetLoadInfo(); MOZ_ASSERT(loadInfo); - loadInfo->SetOriginAttributes(attrs); + if (loadInfo) { + loadInfo->SetOriginAttributes(attrs); + } } void @@ -2107,7 +2113,10 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest *request, nsISupports *ctxt) nsCOMPtr 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 htmlDoc = do_QueryInterface(mResponseXML); @@ -2502,8 +2511,10 @@ XMLHttpRequestMainThread::CreateChannel() } nsCOMPtr 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; } @@ -2608,7 +2619,9 @@ XMLHttpRequestMainThread::InitiateFetch(nsIInputStream* aUploadStream, // Not doing this for privileged system XHRs since those don't use CORS. if (!IsSystemXHR() && !mIsAnon && mFlagACwithCredentials) { nsCOMPtr loadInfo = mChannel->GetLoadInfo(); - static_cast(loadInfo.get())->SetIncludeCookiesSecFlag(); + if (loadInfo) { + static_cast(loadInfo.get())->SetIncludeCookiesSecFlag(); + } } // Blocking gets are common enough out of XHR that we should mark @@ -2669,8 +2682,10 @@ XMLHttpRequestMainThread::InitiateFetch(nsIInputStream* aUploadStream, nsTArray CORSUnsafeHeaders; mAuthorRequestHeaders.GetCORSUnsafeHeaders(CORSUnsafeHeaders); nsCOMPtr 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 diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index e9a2a40c5dcbf..5b109b47edc4a 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -756,7 +756,9 @@ NewImageChannel(nsIChannel** aResult, attrs.Inherit(aLoadingPrincipal->OriginAttributesRef()); nsCOMPtr 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 @@ -788,7 +790,9 @@ NewImageChannel(nsIChannel** aResult, attrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0; nsCOMPtr loadInfo = (*aResult)->GetLoadInfo(); - rv = loadInfo->SetOriginAttributes(attrs); + if (loadInfo) { + rv = loadInfo->SetOriginAttributes(attrs); + } } if (NS_FAILED(rv)) { diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index e7087ab1c2958..14977244021ef 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -942,7 +942,7 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader, mSheet->GetIntegrity(sriMetadata); if (sriMetadata.IsEmpty()) { nsCOMPtr 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")); diff --git a/netwerk/base/Predictor.cpp b/netwerk/base/Predictor.cpp index c63976abf9014..13fd04aeae578 100644 --- a/netwerk/base/Predictor.cpp +++ b/netwerk/base/Predictor.cpp @@ -1352,7 +1352,9 @@ Predictor::Prefetch(nsIURI *uri, nsIURI *referrer, } nsCOMPtr 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)); diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 4b518b7d1bb5c..d2493538bf236 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1267,6 +1267,10 @@ NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport) nsCOMPtr 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; diff --git a/netwerk/protocol/http/InterceptedChannel.cpp b/netwerk/protocol/http/InterceptedChannel.cpp index 9e38e27344809..21fd5c37c8f53 100644 --- a/netwerk/protocol/http/InterceptedChannel.cpp +++ b/netwerk/protocol/http/InterceptedChannel.cpp @@ -346,8 +346,9 @@ InterceptedChannelChrome::GetInternalContentPolicyType(nsContentPolicyType* aPol nsCOMPtr loadInfo; nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_SUCCESS(rv, rv); - - *aPolicyType = loadInfo->InternalContentPolicyType(); + if (loadInfo) { + *aPolicyType = loadInfo->InternalContentPolicyType(); + } return NS_OK; } @@ -515,7 +516,9 @@ InterceptedChannelContent::GetInternalContentPolicyType(nsContentPolicyType* aPo nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_SUCCESS(rv, rv); - *aPolicyType = loadInfo->InternalContentPolicyType(); + if (loadInfo) { + *aPolicyType = loadInfo->InternalContentPolicyType(); + } return NS_OK; } diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index b0cd1c49e1caa..18f9ec70c4e8a 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -867,6 +867,10 @@ CheckUpgradeInsecureRequestsPreventsCORS(nsIPrincipal* aRequestingPrincipal, 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(); diff --git a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp index 8c9a90f3356e6..3dee1b8f8fccb 100644 --- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp +++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp @@ -127,7 +127,9 @@ WyciwygChannelParent::RecvInit(const URIParams& aURI, } nsCOMPtr 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); diff --git a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp index dfb6ac71f6494..5efb1d6a23cf5 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp @@ -133,7 +133,9 @@ nsUrlClassifierStreamUpdater::FetchUpdate(nsIURI *aUpdateUrl, nsCOMPtr loadInfo = mChannel->GetLoadInfo(); mozilla::OriginAttributes attrs; attrs.mFirstPartyDomain.AssignLiteral(NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN); - loadInfo->SetOriginAttributes(attrs); + if (loadInfo) { + loadInfo->SetOriginAttributes(attrs); + } mBeganStream = false; diff --git a/uriloader/prefetch/nsPrefetchService.cpp b/uriloader/prefetch/nsPrefetchService.cpp index bd2b10d3046cb..11a9a5c2de640 100644 --- a/uriloader/prefetch/nsPrefetchService.cpp +++ b/uriloader/prefetch/nsPrefetchService.cpp @@ -202,10 +202,12 @@ nsPrefetchNode::OnStartRequest(nsIRequest *aRequest, // if the load is cross origin without CORS, or the CORS access is rejected, // always fire load event to avoid leaking site information. nsCOMPtr 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;