summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjabdelmalek@google.com <jabdelmalek@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 05:31:41 +0000
committerjabdelmalek@google.com <jabdelmalek@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 05:31:41 +0000
commit2aac77a8652fbe2d82c9e8fde4940dd4a18aa00c (patch)
treea1001779c894afe94efbaea4d49a760fa88776ac /chrome
parentf5e6bd638386378631b6e78c4ea76580d275fab9 (diff)
downloadchromium_src-2aac77a8652fbe2d82c9e8fde4940dd4a18aa00c.zip
chromium_src-2aac77a8652fbe2d82c9e8fde4940dd4a18aa00c.tar.gz
chromium_src-2aac77a8652fbe2d82c9e8fde4940dd4a18aa00c.tar.bz2
Fix problem of safebrowsing database removing an add for a hostname when it got a sub for some prefixes.
BUG=1315628 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1481 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.cc4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util_unittest.cc29
2 files changed, 31 insertions, 2 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.cc b/chrome/browser/safe_browsing/safe_browsing_util.cc
index ba691b0..1731d75 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_util.cc
@@ -505,8 +505,8 @@ void SBHostInfo::RemovePrefixes(SBEntry* sub_entry, bool persist) {
// that host key completely. No need to add this sub chunk to the db.
persist = false;
continue;
- } else if (sub_entry->prefix_count()) {
- // Create another entry that doesn't have these prefixes.
+ } else if (sub_entry->prefix_count() && add_entry->prefix_count()) {
+ // Remove any of the sub prefixes from these add prefixes.
data.reset(new char[add_entry->Size()]);
new_add_entry = reinterpret_cast<SBEntry*>(data.get());
memcpy(new_add_entry, add_entry, add_entry->Size());
diff --git a/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc
index e9a98ea..ad2f258 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc
@@ -235,3 +235,32 @@ TEST(SafeBrowsing, HostInfo) {
EXPECT_FALSE(info.Contains(full_hashes, &list_id, &prefix_hits));
}
+// Checks that if we have a hostname blacklisted and we get a sub prefix, the
+// hostname remains blacklisted.
+TEST(SafeBrowsing, HostInfo2) {
+ // Blacklist the entire hostname.
+ SBEntry* entry = SBEntry::Create(SBEntry::ADD_PREFIX, 0);
+ entry->set_list_id(1);
+ entry->set_chunk_id(1);
+
+ SBHostInfo info;
+ info.AddPrefixes(entry);
+ entry->Destroy();
+
+ int list_id;
+ std::vector<SBFullHash> full_hashes;
+ full_hashes.push_back(CreateFullHash(0x01000000));
+ std::vector<SBPrefix> prefix_hits;
+ EXPECT_TRUE(info.Contains(full_hashes, &list_id, &prefix_hits));
+
+ // Now add a sub prefix.
+ entry = SBEntry::Create(SBEntry::SUB_PREFIX, 1);
+ entry->SetPrefixAt(0, 0x02000000);
+ entry->SetChunkIdAtPrefix(0, 2);
+ entry->set_list_id(1);
+ info.RemovePrefixes(entry, true);
+ entry->Destroy();
+
+ // Any prefix except the one removed should still be blocked.
+ EXPECT_TRUE(info.Contains(full_hashes, &list_id, &prefix_hits));
+}