Skip to content

Commit

Permalink
Bug 1336802 - Part 2: Updating the whole code base to make sure nsILo…
Browse files Browse the repository at this point in the history
…adInfo get null check. r=smaug

--HG--
extra : rebase_source : 22149fd540fd02119afe9fe5c9a815d01cf959c1
  • Loading branch information
artines1 committed Feb 7, 2017
1 parent c44e5b4 commit 756cf90
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 28 deletions.
3 changes: 3 additions & 0 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9831,6 +9831,9 @@ nsContentUtils::AttemptLargeAllocationLoad(nsIHttpChannel* aChannel)
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
Expand Down
1 change: 1 addition & 0 deletions dom/base/nsObjectLoadingContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,7 @@ nsObjectLoadingContent::OpenChannel()
NS_ENSURE_SUCCESS(rv, rv);
if (inherit) {
nsCOMPtr<nsILoadInfo> loadinfo = chan->GetLoadInfo();
NS_ENSURE_STATE(loadinfo);
loadinfo->SetPrincipalToInherit(thisContent->NodePrincipal());
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
} 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;
Expand Down
4 changes: 3 additions & 1 deletion dom/fetch/FetchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ FetchDriver::HttpFetch()
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);
Expand Down
2 changes: 2 additions & 0 deletions dom/html/nsHTMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2318,8 +2318,10 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void)
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);
Expand Down
14 changes: 9 additions & 5 deletions dom/security/nsMixedContentBlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,16 @@ nsMixedContentBlocker::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/workers/ServiceWorkerEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class FinishResponse final : public Runnable
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;
}
Expand Down
2 changes: 2 additions & 0 deletions dom/workers/ServiceWorkerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,10 @@ class FetchEventRunnable : public ExtendableFunctionalEventWorkerRunnable
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?");

Expand Down
29 changes: 22 additions & 7 deletions dom/xhr/XMLHttpRequestMainThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ XMLHttpRequestMainThread::IsCrossSiteCORSRequest() const
nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
MOZ_ASSERT(loadInfo);

if (!loadInfo) {
return false;
}

return loadInfo->GetTainting() == LoadTainting::CORS;
}

Expand Down Expand Up @@ -1608,7 +1612,9 @@ XMLHttpRequestMainThread::SetOriginAttributes(const OriginAttributesDictionary&

nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo();
MOZ_ASSERT(loadInfo);
loadInfo->SetOriginAttributes(attrs);
if (loadInfo) {
loadInfo->SetOriginAttributes(attrs);
}
}

void
Expand Down Expand Up @@ -2107,7 +2113,10 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest *request, nsISupports *ctxt)

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);
Expand Down Expand Up @@ -2502,8 +2511,10 @@ XMLHttpRequestMainThread::CreateChannel()
}

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;
}
Expand Down Expand Up @@ -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<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
Expand Down Expand Up @@ -2669,8 +2682,10 @@ XMLHttpRequestMainThread::InitiateFetch(nsIInputStream* aUploadStream,
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
Expand Down
8 changes: 6 additions & 2 deletions image/imgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ NewImageChannel(nsIChannel** aResult,
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
Expand Down Expand Up @@ -788,7 +790,9 @@ NewImageChannel(nsIChannel** aResult,
attrs.mPrivateBrowsingId = aRespectPrivacy ? 1 : 0;

nsCOMPtr<nsILoadInfo> loadInfo = (*aResult)->GetLoadInfo();
rv = loadInfo->SetOriginAttributes(attrs);
if (loadInfo) {
rv = loadInfo->SetOriginAttributes(attrs);
}
}

if (NS_FAILED(rv)) {
Expand Down
2 changes: 1 addition & 1 deletion layout/style/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
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"));
Expand Down
4 changes: 3 additions & 1 deletion netwerk/base/Predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,9 @@ Predictor::Prefetch(nsIURI *uri, nsIURI *referrer,
}

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));
Expand Down
4 changes: 4 additions & 0 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,10 @@ 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;
Expand Down
9 changes: 6 additions & 3 deletions netwerk/protocol/http/InterceptedChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ InterceptedChannelChrome::GetInternalContentPolicyType(nsContentPolicyType* aPol
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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions netwerk/protocol/http/nsCORSListenerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ WyciwygChannelParent::RecvInit(const URIParams& aURI,
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ nsUrlClassifierStreamUpdater::FetchUpdate(nsIURI *aUpdateUrl,
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;

Expand Down
10 changes: 6 additions & 4 deletions uriloader/prefetch/nsPrefetchService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
Expand Down

0 comments on commit 756cf90

Please sign in to comment.