diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_util.cc | 4 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_util_unittest.cc | 29 |
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)); +} |