summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 01:22:30 +0000
committerpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-08 01:22:30 +0000
commit3b0f5f6fb61bd3a896670d91e8aa42c4e2c772b9 (patch)
treea15d63db3fda923116a959397c0da2023c37f2ee /chrome/browser
parent9162a11c97dd8f1a8a701f5ce04905b0cf41991e (diff)
downloadchromium_src-3b0f5f6fb61bd3a896670d91e8aa42c4e2c772b9.zip
chromium_src-3b0f5f6fb61bd3a896670d91e8aa42c4e2c772b9.tar.gz
chromium_src-3b0f5f6fb61bd3a896670d91e8aa42c4e2c772b9.tar.bz2
Ignore GetHash results for lists that we don't support.
BUG=5597 (http://crbug.com/5597) Review URL: http://codereview.chromium.org/16595 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/safe_browsing/protocol_parser.cc7
-rw-r--r--chrome/browser/safe_browsing/protocol_parser_unittest.cc41
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.cc40
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.h9
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.cc20
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.h9
6 files changed, 85 insertions, 41 deletions
diff --git a/chrome/browser/safe_browsing/protocol_parser.cc b/chrome/browser/safe_browsing/protocol_parser.cc
index dcfd247..0359a1c 100644
--- a/chrome/browser/safe_browsing/protocol_parser.cc
+++ b/chrome/browser/safe_browsing/protocol_parser.cc
@@ -90,6 +90,13 @@ bool SafeBrowsingProtocolParser::ParseGetHash(
full_hash.add_chunk_id = atoi(cmd_parts[1].c_str());
int full_hash_len = atoi(cmd_parts[2].c_str());
+ // Ignore hash results from lists we don't recognize.
+ if (safe_browsing_util::GetListId(full_hash.list_name) < 0) {
+ data += full_hash_len;
+ length -= full_hash_len;
+ continue;
+ }
+
while (full_hash_len > 0) {
DCHECK(static_cast<size_t>(full_hash_len) >= sizeof(SBFullHash));
memcpy(&full_hash.hash, data, sizeof(SBFullHash));
diff --git a/chrome/browser/safe_browsing/protocol_parser_unittest.cc b/chrome/browser/safe_browsing/protocol_parser_unittest.cc
index b5799cd..e651c14 100644
--- a/chrome/browser/safe_browsing/protocol_parser_unittest.cc
+++ b/chrome/browser/safe_browsing/protocol_parser_unittest.cc
@@ -491,6 +491,47 @@ TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithMac) {
EXPECT_EQ(memcmp(hash_result, &full_hashes[0].hash, sizeof(SBFullHash)), 0);
}
+TEST(SafeBrowsingProtocolParsingTest, TestGetHashWithUnknownList) {
+ std::string hash_response = "goog-phish-shavar:1:32\n"
+ "12345678901234567890123456789012"
+ "googpub-phish-shavar:19:32\n"
+ "09876543210987654321098765432109";
+ bool re_key = false;
+ std::string key = "";
+ std::vector<SBFullHashResult> full_hashes;
+ SafeBrowsingProtocolParser parser;
+ EXPECT_TRUE(parser.ParseGetHash(hash_response.data(),
+ hash_response.size(),
+ key,
+ &re_key,
+ &full_hashes));
+
+ EXPECT_EQ(full_hashes.size(), 1);
+ EXPECT_EQ(memcmp("12345678901234567890123456789012",
+ &full_hashes[0].hash, sizeof(SBFullHash)), 0);
+ EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar");
+ EXPECT_EQ(full_hashes[0].add_chunk_id, 1);
+
+ hash_response += "goog-malware-shavar:7:32\n"
+ "abcdefghijklmnopqrstuvwxyz123457";
+ full_hashes.clear();
+ EXPECT_TRUE(parser.ParseGetHash(hash_response.data(),
+ hash_response.size(),
+ key,
+ &re_key,
+ &full_hashes));
+
+ EXPECT_EQ(full_hashes.size(), 2);
+ EXPECT_EQ(memcmp("12345678901234567890123456789012",
+ &full_hashes[0].hash, sizeof(SBFullHash)), 0);
+ EXPECT_EQ(full_hashes[0].list_name, "goog-phish-shavar");
+ EXPECT_EQ(full_hashes[0].add_chunk_id, 1);
+ EXPECT_EQ(memcmp("abcdefghijklmnopqrstuvwxyz123457",
+ &full_hashes[1].hash, sizeof(SBFullHash)), 0);
+ EXPECT_EQ(full_hashes[1].list_name, "goog-malware-shavar");
+ EXPECT_EQ(full_hashes[1].add_chunk_id, 7);
+}
+
TEST(SafeBrowsingProtocolParsingTest, TestFormatHash) {
SafeBrowsingProtocolParser parser;
std::vector<SBPrefix> prefixes;
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
index 6f2740f..ef188d7 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
@@ -361,7 +361,7 @@ void SafeBrowsingDatabaseBloom::InsertChunks(const std::string& list_name,
base::Time insert_start = base::Time::Now();
- int list_id = GetListId(list_name);
+ int list_id = safe_browsing_util::GetListId(list_name);
ChunkType chunk_type = chunks->front().is_add ? ADD_CHUNK : SUB_CHUNK;
while (!chunks->empty()) {
@@ -637,7 +637,7 @@ void SafeBrowsingDatabaseBloom::DeleteChunks(
if (chunk_deletes->empty())
return;
- int list_id = GetListId(chunk_deletes->front().list_name);
+ int list_id = safe_browsing_util::GetListId(chunk_deletes->front().list_name);
for (size_t i = 0; i < chunk_deletes->size(); ++i) {
const SBChunkDelete& chunk = (*chunk_deletes)[i];
@@ -703,40 +703,16 @@ void SafeBrowsingDatabaseBloom::GetListsInfo(
ReadChunkNumbers();
lists->push_back(SBListChunkRanges(safe_browsing_util::kMalwareList));
- GetChunkIds(MALWARE, ADD_CHUNK, &lists->back().adds);
- GetChunkIds(MALWARE, SUB_CHUNK, &lists->back().subs);
+ GetChunkIds(safe_browsing_util::MALWARE, ADD_CHUNK, &lists->back().adds);
+ GetChunkIds(safe_browsing_util::MALWARE, SUB_CHUNK, &lists->back().subs);
lists->push_back(SBListChunkRanges(safe_browsing_util::kPhishingList));
- GetChunkIds(PHISH, ADD_CHUNK, &lists->back().adds);
- GetChunkIds(PHISH, SUB_CHUNK, &lists->back().subs);
+ GetChunkIds(safe_browsing_util::PHISH, ADD_CHUNK, &lists->back().adds);
+ GetChunkIds(safe_browsing_util::PHISH, SUB_CHUNK, &lists->back().subs);
return;
}
-/* static */
-int SafeBrowsingDatabaseBloom::GetListId(const std::string& name) {
- if (name == safe_browsing_util::kMalwareList)
- return MALWARE;
- else if (name == safe_browsing_util::kPhishingList)
- return PHISH;
-
- NOTREACHED();
- return -1;
-}
-
-/* static */
-std::string SafeBrowsingDatabaseBloom::GetListName(int list_id) {
- switch (list_id) {
- case MALWARE:
- return safe_browsing_util::kMalwareList;
- case PHISH:
- return safe_browsing_util::kPhishingList;
- default:
- NOTREACHED();
- return "";
- }
-}
-
void SafeBrowsingDatabaseBloom::ReadChunkNumbers() {
add_chunk_cache_.clear();
sub_chunk_cache_.clear();
@@ -1413,7 +1389,7 @@ void SafeBrowsingDatabaseBloom::GetCachedFullHashes(
memcpy(&full_hash.hash.full_hash,
&eit->full_hash.full_hash,
sizeof(SBFullHash));
- full_hash.list_name = GetListName(eit->list_id);
+ full_hash.list_name = safe_browsing_util::GetListName(eit->list_id);
full_hash.add_chunk_id = eit->add_chunk_id;
full_hits->push_back(full_hash);
}
@@ -1449,7 +1425,7 @@ void SafeBrowsingDatabaseBloom::CacheHashResults(
HashList& entries = (*hash_cache_)[prefix];
HashCacheEntry entry;
entry.received = now;
- entry.list_id = GetListId(it->list_name);
+ entry.list_id = safe_browsing_util::GetListId(it->list_name);
entry.add_chunk_id = EncodeChunkId(it->add_chunk_id, entry.list_id);
memcpy(&entry.full_hash, &it->hash.full_hash, sizeof(SBFullHash));
entries.push_back(entry);
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.h b/chrome/browser/safe_browsing/safe_browsing_database_bloom.h
index a7db0f2..c04d872 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.h
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.h
@@ -111,15 +111,6 @@ class SafeBrowsingDatabaseBloom : public SafeBrowsingDatabase {
// the given list and chunk type.
void GetChunkIds(int list_id, ChunkType type, std::string* list);
- // Converts between the SafeBrowsing list names and their enumerated value.
- // If the list names change, both of these methods must be updated.
- enum ListType {
- MALWARE = 0,
- PHISH = 1,
- };
- static int GetListId(const std::string& name);
- static std::string GetListName(int list_id);
-
// Generate a bloom filter.
virtual void BuildBloomFilter();
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.cc b/chrome/browser/safe_browsing/safe_browsing_util.cc
index 7b529fa..fcc185b 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_util.cc
@@ -28,6 +28,26 @@ namespace safe_browsing_util {
const char kMalwareList[] = "goog-malware-shavar";
const char kPhishingList[] = "goog-phish-shavar";
+int GetListId(const std::string& name) {
+ if (name == kMalwareList)
+ return MALWARE;
+ else if (name == kPhishingList)
+ return PHISH;
+
+ return -1;
+}
+
+std::string GetListName(int list_id) {
+ switch (list_id) {
+ case MALWARE:
+ return kMalwareList;
+ case PHISH:
+ return kPhishingList;
+ default:
+ return "";
+ }
+}
+
void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts) {
// Per Safe Browsing Protocol 2 spec, first we try the host. Then we try up
// to 4 hostnames starting with the last 5 components and successively
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.h b/chrome/browser/safe_browsing/safe_browsing_util.h
index a034b73..a184ca6 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.h
+++ b/chrome/browser/safe_browsing/safe_browsing_util.h
@@ -277,6 +277,15 @@ namespace safe_browsing_util {
extern const char kMalwareList[];
extern const char kPhishingList[];
+// Converts between the SafeBrowsing list names and their enumerated value.
+// If the list names change, both of these methods must be updated.
+enum ListType {
+ MALWARE = 0,
+ PHISH = 1,
+};
+int GetListId(const std::string& name);
+std::string GetListName(int list_id);
+
void FreeChunks(std::deque<SBChunk>* chunks);
// Given a URL, returns all the hosts we need to check. They are returned