Bug 1100338 - Do not consider noise for Completion matches. Remove dead code. r=francois

This commit is contained in:
Gian-Carlo Pascutto 2015-07-06 04:24:00 +02:00
parent 854efb9851
commit 760f31a46e
4 changed files with 17 additions and 66 deletions

View File

@ -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);

View File

@ -372,51 +372,6 @@ LookupCache::IsCanonicalizedIP(const nsACString& aHost)
return false;
}
/* static */ nsresult
LookupCache::GetKey(const nsACString& aSpec,
Completion* aHash,
nsCOMPtr<nsICryptoHash>& 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<nsCString> 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<nsCString>* aFragments)

View File

@ -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<nsCString>* 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<nsICryptoHash>& aCryptoHash);
LookupCache(const nsACString& aTableName, nsIFile* aStoreFile);
~LookupCache();

View File

@ -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;
}
}