From 53b093b51a10427a0daf2493b2ff60ca7dab5a7a Mon Sep 17 00:00:00 2001 From: Oskar Mansfeld Date: Thu, 17 Oct 2024 08:39:40 +0000 Subject: [PATCH] Bug 1873874 - Fixed crash due to empty mTargetURI when calling Predictor::Action::OnCacheEntryAvailable, r=necko-reviewers,kershaw There was a bug where the Action was getting initialized with the wrong URI, thus mTargerURI staying empty. Also added an errorcheck to OnCacheEntryAvailable so even if an empty URI sneaks in from somewhere else it doesn't just crash. Differential Revision: https://phabricator.services.mozilla.com/D225181 --- netwerk/base/Predictor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netwerk/base/Predictor.cpp b/netwerk/base/Predictor.cpp index cafd5a559f60..c9eb3c518904 100644 --- a/netwerk/base/Predictor.cpp +++ b/netwerk/base/Predictor.cpp @@ -181,6 +181,9 @@ Predictor::Action::OnCacheEntryAvailable(nsICacheEntry* entry, bool isNew, MOZ_ASSERT(NS_IsMainThread(), "Got cache entry off main thread!"); nsAutoCString targetURI, sourceURI; + if (!mTargetURI) { + return NS_ERROR_UNEXPECTED; + } mTargetURI->GetAsciiSpec(targetURI); if (mSourceURI) { mSourceURI->GetAsciiSpec(sourceURI); @@ -571,7 +574,7 @@ Predictor::PredictNative(nsIURI* targetURI, nsIURI* sourceURI, // waiting on the less-important predictor-only cache entry RefPtr uriAction = new Predictor::Action( Predictor::Action::IS_FULL_URI, Predictor::Action::DO_PREDICT, argReason, - targetURI, nullptr, verifier, this); + uriKey, nullptr, verifier, this); nsAutoCString uriKeyStr; uriKey->GetAsciiSpec(uriKeyStr); PREDICTOR_LOG((" Predict uri=%s reason=%d action=%p", uriKeyStr.get(),