mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
Bug 420380: Allow safebrowsing gethash responses that don't match table name/chunk id. r=tony, blocking-firefox3=beltzner
This commit is contained in:
parent
a69ef8533a
commit
6a4e998241
@ -3268,12 +3268,7 @@ nsUrlClassifierLookupCallback::Completion(const nsACString& completeHash,
|
||||
|
||||
if (!result.mEntry.mHaveComplete &&
|
||||
hash.StartsWith(result.mEntry.mPartialHash) &&
|
||||
// XXX: We really want to be comparing the table name to make
|
||||
// sure it matches. Due to a short-lived server bug, they
|
||||
// won't just yet. This should be fixed as soon as the server is.
|
||||
#if 0
|
||||
result.mTableName == tableName &&
|
||||
#endif
|
||||
result.mEntry.mChunkId == chunkId) {
|
||||
// We have a completion for this entry. Fill it in...
|
||||
result.mEntry.SetHash(hash);
|
||||
@ -3293,6 +3288,20 @@ nsUrlClassifierLookupCallback::Completion(const nsACString& completeHash,
|
||||
|
||||
mCacheResults->AppendElement(result);
|
||||
}
|
||||
} else if (result.mLookupFragment == hash) {
|
||||
// The hash we got for this completion matches the hash we
|
||||
// looked up, but doesn't match the table/chunk id. This could
|
||||
// happen in rare cases where a given URL was moved between
|
||||
// lists or added/removed/re-added to the list in the time since
|
||||
// we've updated.
|
||||
//
|
||||
// Update the lookup result, but don't update the entry or try
|
||||
// caching the results of this completion, as it might confuse
|
||||
// things.
|
||||
result.mConfirmed = PR_TRUE;
|
||||
result.mTableName = tableName;
|
||||
|
||||
NS_WARNING("Accepting a gethash with an invalid table name or chunk id");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ function DummyCompleter() {
|
||||
this.fragments = {};
|
||||
this.queries = [];
|
||||
this.cachable = true;
|
||||
this.tableName = "test-phish-simple";
|
||||
}
|
||||
|
||||
DummyCompleter.prototype =
|
||||
@ -35,7 +36,7 @@ complete: function(partialHash, cb)
|
||||
for (var i = 0; i < fragments[partialHash].length; i++) {
|
||||
var chunkId = fragments[partialHash][i][0];
|
||||
var hash = fragments[partialHash][i][1];
|
||||
cb.completion(hash, "test-phish-simple", chunkId, self.cachable);
|
||||
cb.completion(hash, self.tableName, chunkId, self.cachable);
|
||||
}
|
||||
}
|
||||
cb.completionFinished(0);
|
||||
@ -99,6 +100,7 @@ compareQueries: function(fragments)
|
||||
function setupCompleter(table, hits, conflicts)
|
||||
{
|
||||
var completer = new DummyCompleter();
|
||||
completer.tableName = table;
|
||||
for (var i = 0; i < hits.length; i++) {
|
||||
var chunkId = hits[i][0];
|
||||
var fragments = hits[i][1];
|
||||
@ -347,11 +349,46 @@ function testWrongTable()
|
||||
{ "chunkNum" : 1,
|
||||
"urls" : addUrls
|
||||
}],
|
||||
32);
|
||||
4);
|
||||
var completer = installCompleter('test-malware-simple', // wrong table
|
||||
[[1, addUrls]]);
|
||||
[[1, addUrls]], []);
|
||||
|
||||
doTest([update], assertions);
|
||||
// The above installCompleter installs the completer for test-malware-simple,
|
||||
// we want it to be used for test-phish-simple too.
|
||||
dbservice.setHashCompleter("test-phish-simple", completer);
|
||||
|
||||
|
||||
var assertions = {
|
||||
"tableData" : "test-phish-simple;a:1",
|
||||
// The urls were added as phishing urls, but the completer is claiming
|
||||
// that they are malware urls, and we trust the completer in this case.
|
||||
"malwareUrlsExist" : addUrls,
|
||||
// Make sure the completer was actually queried.
|
||||
"completerQueried" : [completer, addUrls]
|
||||
};
|
||||
|
||||
doUpdateTest([update], assertions,
|
||||
function() {
|
||||
// Give the dbservice a chance to (not) cache the result.
|
||||
var timer = new Timer(3000, function() {
|
||||
// The dbservice shouldn't have cached this result,
|
||||
// so this completer should be queried.
|
||||
var newCompleter = installCompleter('test-malware-simple', [[1, addUrls]], []);
|
||||
|
||||
// The above installCompleter installs the
|
||||
// completer for test-malware-simple, we want it
|
||||
// to be used for test-phish-simple too.
|
||||
dbservice.setHashCompleter("test-phish-simple",
|
||||
newCompleter);
|
||||
|
||||
|
||||
var assertions = {
|
||||
"malwareUrlsExist" : addUrls,
|
||||
"completerQueried" : [newCompleter, addUrls]
|
||||
};
|
||||
checkAssertions(assertions, runNextTest);
|
||||
});
|
||||
}, updateError);
|
||||
}
|
||||
|
||||
function testWrongChunk()
|
||||
@ -362,12 +399,33 @@ function testWrongChunk()
|
||||
{ "chunkNum" : 1,
|
||||
"urls" : addUrls
|
||||
}],
|
||||
32);
|
||||
4);
|
||||
var completer = installCompleter('test-phish-simple',
|
||||
[[2, // Wrong chunk number
|
||||
addUrls]]);
|
||||
[[2, // wrong chunk number
|
||||
addUrls]], []);
|
||||
|
||||
doTest([update], assertions);
|
||||
var assertions = {
|
||||
"tableData" : "test-phish-simple;a:1",
|
||||
"urlsExist" : addUrls,
|
||||
// Make sure the completer was actually queried.
|
||||
"completerQueried" : [completer, addUrls]
|
||||
};
|
||||
|
||||
doUpdateTest([update], assertions,
|
||||
function() {
|
||||
// Give the dbservice a chance to (not) cache the result.
|
||||
var timer = new Timer(3000, function() {
|
||||
// The dbservice shouldn't have cached this result,
|
||||
// so this completer should be queried.
|
||||
var newCompleter = installCompleter('test-phish-simple', [[2, addUrls]], []);
|
||||
|
||||
var assertions = {
|
||||
"urlsExist" : addUrls,
|
||||
"completerQueried" : [newCompleter, addUrls]
|
||||
};
|
||||
checkAssertions(assertions, runNextTest);
|
||||
});
|
||||
}, updateError);
|
||||
}
|
||||
|
||||
function setupCachedResults(addUrls, part2)
|
||||
@ -505,6 +563,8 @@ function run_test()
|
||||
testMixedSizesSameDomain,
|
||||
testMixedSizesDifferentDomains,
|
||||
testInvalidHashSize,
|
||||
testWrongTable,
|
||||
testWrongChunk,
|
||||
testCachedResults,
|
||||
testCachedResultsWithSub,
|
||||
testCachedResultsWithExpire,
|
||||
|
Loading…
Reference in New Issue
Block a user