Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: chrome/browser/safe_browsing/protocol_parser.cc

Issue 582143002: Safebrowsing: Fix failure parsing a gethash result with bad listname and metadata. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add todo Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/protocol_parser.cc
diff --git a/chrome/browser/safe_browsing/protocol_parser.cc b/chrome/browser/safe_browsing/protocol_parser.cc
index 82cbce79d935fc9f6ebf720dddd52df9f2fc9d92..790dda554f1decef871d1582adcd2fb3d448c8f4 100644
--- a/chrome/browser/safe_browsing/protocol_parser.cc
+++ b/chrome/browser/safe_browsing/protocol_parser.cc
@@ -131,6 +131,23 @@ class BufferReader {
DISALLOW_COPY_AND_ASSIGN(BufferReader);
};
+bool ParseGetHashMetadata(size_t hash_count, BufferReader* reader) {
+ for (size_t i = 0; i < hash_count; ++i) {
+ base::StringPiece line;
+ if (!reader->GetLine(&line))
+ return false;
+
+ size_t meta_data_len;
+ if (!base::StringToSizeT(line, &meta_data_len))
+ return false;
+
+ const void* meta_data;
+ if (!reader->RefData(&meta_data, meta_data_len))
+ return false;
+ }
+ return true;
+}
+
} // namespace
namespace safe_browsing {
@@ -206,6 +223,8 @@ bool ParseGetHash(const char* chunk_data,
// Ignore hash results from lists we don't recognize.
if (full_hash.list_id < 0) {
reader.Advance(hash_len * hash_count);
+ if (has_metadata && !ParseGetHashMetadata(hash_count, &reader))
+ return false;
continue;
}
@@ -216,21 +235,9 @@ bool ParseGetHash(const char* chunk_data,
}
// Discard the metadata for now.
- if (has_metadata) {
- for (size_t i = 0; i < hash_count; ++i) {
- base::StringPiece line;
- if (!reader.GetLine(&line))
- return false;
-
- size_t meta_data_len;
- if (!base::StringToSizeT(line, &meta_data_len))
- return false;
-
- const void* meta_data;
- if (!reader.RefData(&meta_data, meta_data_len))
- return false;
- }
- }
+ // TODO(mattm): handle the metadata (see crbug.com/176648).
+ if (has_metadata && !ParseGetHashMetadata(hash_count, &reader))
+ return false;
}
return reader.empty();
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698