зеркало из https://github.com/mozilla/pjs.git
Bug 475436: reloading a blocked page would bypass blocking in some cases. r=tony
This commit is contained in:
Родитель
f60528cf06
Коммит
ff4ec550e2
|
@ -1183,10 +1183,12 @@ private:
|
||||||
nsresult GetHostKeys(const nsACString &spec,
|
nsresult GetHostKeys(const nsACString &spec,
|
||||||
nsTArray<nsCString> &hostKeys);
|
nsTArray<nsCString> &hostKeys);
|
||||||
|
|
||||||
|
// Read all relevant entries for the given URI into mCachedEntries.
|
||||||
|
nsresult CacheEntries(const nsCSubstring& spec);
|
||||||
|
|
||||||
// Look for a given lookup string (www.hostname.com/path/to/resource.html)
|
// Look for a given lookup string (www.hostname.com/path/to/resource.html)
|
||||||
// in the entries at the given key. Returns a list of entries that match.
|
// Returns a list of entries that match.
|
||||||
nsresult CheckKey(const nsCSubstring& spec,
|
nsresult Check(const nsCSubstring& spec,
|
||||||
const nsACString& key,
|
|
||||||
nsTArray<nsUrlClassifierLookupResult>& results);
|
nsTArray<nsUrlClassifierLookupResult>& results);
|
||||||
|
|
||||||
// Perform a classifier lookup for a given url.
|
// Perform a classifier lookup for a given url.
|
||||||
|
@ -1534,41 +1536,76 @@ nsUrlClassifierDBServiceWorker::GetLookupFragments(const nsACString& spec,
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsUrlClassifierDBServiceWorker::CheckKey(const nsACString& spec,
|
nsUrlClassifierDBServiceWorker::CacheEntries(const nsACString& spec)
|
||||||
const nsACString& hostKey,
|
|
||||||
nsTArray<nsUrlClassifierLookupResult>& results)
|
|
||||||
{
|
{
|
||||||
// First, if this key has been checked since our last update and had
|
nsAutoTArray<nsCString, 2> lookupHosts;
|
||||||
// no entries, we can exit early. We also do this check before
|
nsresult rv = GetHostKeys(spec, lookupHosts);
|
||||||
// posting the lookup to this thread, but in case multiple lookups
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
// are queued at the same time, it's worth checking again here.
|
|
||||||
{
|
// Build a unique string for this set of lookup hosts.
|
||||||
nsAutoLock lock(mCleanHostKeysLock);
|
nsCAutoString hostKey;
|
||||||
if (mCleanHostKeys.Has(hostKey))
|
for (PRUint32 i = 0; i < lookupHosts.Length(); i++) {
|
||||||
|
hostKey.Append(lookupHosts[i]);
|
||||||
|
hostKey.Append("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hostKey == mCachedHostKey) {
|
||||||
|
// mCachedHostKeys is valid for this set of lookup hosts.
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now read host key entries from the db if necessary.
|
|
||||||
if (hostKey != mCachedHostKey) {
|
|
||||||
mCachedEntries.Clear();
|
mCachedEntries.Clear();
|
||||||
nsUrlClassifierDomainHash hostKeyHash;
|
mCachedHostKey.Truncate();
|
||||||
hostKeyHash.FromPlaintext(hostKey, mCryptoHash);
|
|
||||||
mMainStore.ReadAddEntries(hostKeyHash, mCachedEntries);
|
PRUint32 prevLength = 0;
|
||||||
mCachedHostKey = hostKey;
|
for (PRUint32 i = 0; i < lookupHosts.Length(); i++) {
|
||||||
|
// First, if this key has been checked since our last update and
|
||||||
|
// had no entries, we don't need to check the DB here. We also do
|
||||||
|
// this check before posting the lookup to this thread, but in
|
||||||
|
// case multiple lookups are queued at the same time, it's worth
|
||||||
|
// checking again here.
|
||||||
|
{
|
||||||
|
nsAutoLock lock(mCleanHostKeysLock);
|
||||||
|
if (mCleanHostKeys.Has(lookupHosts[i]))
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mCachedEntries.Length() == 0) {
|
// Read the entries for this lookup houst
|
||||||
// There were no entries in the db for this host key. Go ahead
|
nsUrlClassifierDomainHash hostKeyHash;
|
||||||
// and mark the host key as clean to help short-circuit future
|
hostKeyHash.FromPlaintext(lookupHosts[i], mCryptoHash);
|
||||||
// lookups.
|
mMainStore.ReadAddEntries(hostKeyHash, mCachedEntries);
|
||||||
|
|
||||||
|
if (mCachedEntries.Length() == prevLength) {
|
||||||
|
// There were no entries in the db for this host key. Go
|
||||||
|
// ahead and mark the host key as clean to help short-circuit
|
||||||
|
// future lookups.
|
||||||
nsAutoLock lock(mCleanHostKeysLock);
|
nsAutoLock lock(mCleanHostKeysLock);
|
||||||
mCleanHostKeys.Put(hostKey);
|
mCleanHostKeys.Put(lookupHosts[i]);
|
||||||
|
} else {
|
||||||
|
prevLength = mCachedEntries.Length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mCachedHostKey = hostKey;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsUrlClassifierDBServiceWorker::Check(const nsACString& spec,
|
||||||
|
nsTArray<nsUrlClassifierLookupResult>& results)
|
||||||
|
{
|
||||||
|
// Read any entries that might apply to this URI into mCachedEntries
|
||||||
|
nsresult rv = CacheEntries(spec);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
if (mCachedEntries.Length() == 0) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now get the set of fragments to look up.
|
// Now get the set of fragments to look up.
|
||||||
nsTArray<nsCString> fragments;
|
nsTArray<nsCString> fragments;
|
||||||
nsresult rv = GetLookupFragments(spec, fragments);
|
rv = GetLookupFragments(spec, fragments);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
PRInt64 now = (PR_Now() / PR_USEC_PER_SEC);
|
PRInt64 now = (PR_Now() / PR_USEC_PER_SEC);
|
||||||
|
@ -1671,14 +1708,9 @@ nsUrlClassifierDBServiceWorker::DoLookup(const nsACString& spec,
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoTArray<nsCString, 2> lookupHosts;
|
// we ignore failures from Check because we'd rather return the
|
||||||
rv = GetHostKeys(spec, lookupHosts);
|
// results that were found than fail.
|
||||||
|
Check(spec, *results);
|
||||||
for (PRUint32 i = 0; i < lookupHosts.Length(); i++) {
|
|
||||||
// we ignore failures from CheckKey because we'd rather try to
|
|
||||||
// find more results than fail.
|
|
||||||
CheckKey(spec, lookupHosts[i], *results);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(PR_LOGGING)
|
#if defined(PR_LOGGING)
|
||||||
if (LOG_ENABLED()) {
|
if (LOG_ENABLED()) {
|
||||||
|
|
|
@ -176,6 +176,22 @@ function testResetFullCache() {
|
||||||
var t = new Timer(3000, runInitialLookup);
|
var t = new Timer(3000, runInitialLookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testBug475436() {
|
||||||
|
var addUrls = [ "foo.com/a", "www.foo.com/" ];
|
||||||
|
var update = buildPhishingUpdate(
|
||||||
|
[
|
||||||
|
{ "chunkNum" : 1,
|
||||||
|
"urls" : addUrls
|
||||||
|
}]);
|
||||||
|
|
||||||
|
var assertions = {
|
||||||
|
"tableData" : "test-phish-simple;a:1",
|
||||||
|
"urlsExist" : ["foo.com/a", "foo.com/a" ]
|
||||||
|
};
|
||||||
|
|
||||||
|
doUpdateTest([update], assertions, runNextTest, updateError);
|
||||||
|
}
|
||||||
|
|
||||||
function run_test()
|
function run_test()
|
||||||
{
|
{
|
||||||
runTests([
|
runTests([
|
||||||
|
@ -186,6 +202,7 @@ function run_test()
|
||||||
testCleanHostKeys,
|
testCleanHostKeys,
|
||||||
testDirtyHostKeys,
|
testDirtyHostKeys,
|
||||||
testResetFullCache,
|
testResetFullCache,
|
||||||
|
testBug475436
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче