diff --git a/toolkit/components/url-classifier/Classifier.cpp b/toolkit/components/url-classifier/Classifier.cpp index 43ed71a4b61e..2adae10967c8 100644 --- a/toolkit/components/url-classifier/Classifier.cpp +++ b/toolkit/components/url-classifier/Classifier.cpp @@ -243,14 +243,6 @@ Classifier::Check(const nsACString& aSpec, Completion lookupHash; lookupHash.FromPlaintext(fragments[i], mCryptoHash); - // Get list of host keys to look up - Completion hostKey; - rv = LookupCache::GetKey(fragments[i], &hostKey, mCryptoHash); - if (NS_FAILED(rv)) { - // Local host on the network. - continue; - } - if (LOG_ENABLED()) { nsAutoCString checking; lookupHash.ToHexString(checking); diff --git a/toolkit/components/url-classifier/LookupCache.cpp b/toolkit/components/url-classifier/LookupCache.cpp index 1899fe5b916d..7e2c2cf3f0ec 100644 --- a/toolkit/components/url-classifier/LookupCache.cpp +++ b/toolkit/components/url-classifier/LookupCache.cpp @@ -372,51 +372,6 @@ LookupCache::IsCanonicalizedIP(const nsACString& aHost) return false; } -/* static */ nsresult -LookupCache::GetKey(const nsACString& aSpec, - Completion* aHash, - nsCOMPtr& aCryptoHash) -{ - nsACString::const_iterator begin, end, iter; - aSpec.BeginReading(begin); - aSpec.EndReading(end); - - iter = begin; - if (!FindCharInReadable('/', iter, end)) { - return NS_OK; - } - - const nsCSubstring& host = Substring(begin, iter); - - if (IsCanonicalizedIP(host)) { - nsAutoCString key; - key.Assign(host); - key.Append('/'); - return aHash->FromPlaintext(key, aCryptoHash); - } - - nsTArray hostComponents; - ParseString(PromiseFlatCString(host), '.', hostComponents); - - if (hostComponents.Length() < 2) - return NS_ERROR_FAILURE; - - int32_t last = int32_t(hostComponents.Length()) - 1; - nsAutoCString lookupHost; - - if (hostComponents.Length() > 2) { - lookupHost.Append(hostComponents[last - 2]); - lookupHost.Append('.'); - } - - lookupHost.Append(hostComponents[last - 1]); - lookupHost.Append('.'); - lookupHost.Append(hostComponents[last]); - lookupHost.Append('/'); - - return aHash->FromPlaintext(lookupHost, aCryptoHash); -} - /* static */ nsresult LookupCache::GetLookupFragments(const nsACString& aSpec, nsTArray* aFragments) diff --git a/toolkit/components/url-classifier/LookupCache.h b/toolkit/components/url-classifier/LookupCache.h index 4e4387bda4e7..885c352e60f0 100644 --- a/toolkit/components/url-classifier/LookupCache.h +++ b/toolkit/components/url-classifier/LookupCache.h @@ -24,7 +24,8 @@ namespace safebrowsing { class LookupResult { public: - LookupResult() : mComplete(false), mNoise(false), mFresh(false), mProtocolConfirmed(false) {} + LookupResult() : mComplete(false), mNoise(false), + mFresh(false), mProtocolConfirmed(false) {} // The fragment that matched in the LookupCache union { @@ -32,8 +33,13 @@ public: Completion complete; } hash; - const Prefix &PrefixHash() { return hash.prefix; } - const Completion &CompleteHash() { return hash.complete; } + const Prefix &PrefixHash() { + return hash.prefix; + } + const Completion &CompleteHash() { + MOZ_ASSERT(!mNoise); + return hash.complete; + } bool Confirmed() const { return (mComplete && mFresh) || mProtocolConfirmed; } bool Complete() const { return mComplete; } @@ -42,7 +48,10 @@ public: bool mComplete; // True if this is a noise entry, i.e. an extra entry - // that is inserted to mask the true URL we are requesting + // that is inserted to mask the true URL we are requesting. + // Noise entries will not have a complete 256-bit hash as + // they are fetched from the local 32-bit database and we + // don't know the corresponding full URL. bool mNoise; // True if we've updated this table recently-enough. @@ -78,13 +87,6 @@ public: // www.mail.hostname.com/foo/bar -> [hostname.com, mail.hostname.com] static nsresult GetHostKeys(const nsACString& aSpec, nsTArray* aHostKeys); - // Get the database key for a given URI. This is the top three - // domain components if they exist, otherwise the top two. - // hostname.com/foo/bar -> hostname.com - // mail.hostname.com/foo/bar -> mail.hostname.com - // www.mail.hostname.com/foo/bar -> mail.hostname.com - static nsresult GetKey(const nsACString& aSpec, Completion* aHash, - nsCOMPtr& aCryptoHash); LookupCache(const nsACString& aTableName, nsIFile* aStoreFile); ~LookupCache(); diff --git a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp index dedf8fed2b8e..4fa251357d0b 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp @@ -705,7 +705,7 @@ nsUrlClassifierDBServiceWorker::CacheMisses(PrefixArray *results) for (uint32_t i = 0; i < resultsPtr->Length(); i++) { mMissCache.AppendElement(resultsPtr->ElementAt(i)); - } + } return NS_OK; } @@ -914,7 +914,9 @@ nsUrlClassifierLookupCallback::Completion(const nsACString& completeHash, LookupResult& result = mResults->ElementAt(i); // Now, see if it verifies a lookup - if (result.CompleteHash() == hash && result.mTableName.Equals(tableName)) { + if (!result.mNoise + && result.CompleteHash() == hash + && result.mTableName.Equals(tableName)) { result.mProtocolConfirmed = true; } }