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

Side by Side Diff: chrome/browser/safe_browsing/protocol_parser.cc

Issue 586793003: Safebrowsing: Honor the metadata from malware fullhash results in SB API 3.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes for sky 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Parse the data returned from the SafeBrowsing v2.1 protocol response. 5 // Parse the data returned from the SafeBrowsing v2.1 protocol response.
6 6
7 // TODOv3(shess): Review these changes carefully. 7 // TODOv3(shess): Review these changes carefully.
8 8
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return true; 124 return true;
125 } 125 }
126 126
127 private: 127 private:
128 const char* data_; 128 const char* data_;
129 size_t length_; 129 size_t length_;
130 130
131 DISALLOW_COPY_AND_ASSIGN(BufferReader); 131 DISALLOW_COPY_AND_ASSIGN(BufferReader);
132 }; 132 };
133 133
134 bool ParseGetHashMetadata(size_t hash_count, BufferReader* reader) { 134 bool ParseGetHashMetadata(size_t hash_count,
135 BufferReader* reader,
136 std::vector<SBFullHashResult>* full_hashes) {
135 for (size_t i = 0; i < hash_count; ++i) { 137 for (size_t i = 0; i < hash_count; ++i) {
136 base::StringPiece line; 138 base::StringPiece line;
137 if (!reader->GetLine(&line)) 139 if (!reader->GetLine(&line))
138 return false; 140 return false;
139 141
140 size_t meta_data_len; 142 size_t meta_data_len;
141 if (!base::StringToSizeT(line, &meta_data_len)) 143 if (!base::StringToSizeT(line, &meta_data_len))
142 return false; 144 return false;
143 145
144 const void* meta_data; 146 const void* meta_data;
145 if (!reader->RefData(&meta_data, meta_data_len)) 147 if (!reader->RefData(&meta_data, meta_data_len))
146 return false; 148 return false;
149
150 if (full_hashes) {
151 (*full_hashes)[full_hashes->size() - hash_count + i].metadata.assign(
152 reinterpret_cast<const char*>(meta_data), meta_data_len);
153 }
147 } 154 }
148 return true; 155 return true;
149 } 156 }
150 157
151 } // namespace 158 } // namespace
152 159
153 namespace safe_browsing { 160 namespace safe_browsing {
154 161
155 // BODY = CACHELIFETIME LF HASHENTRY* EOF 162 // BODY = CACHELIFETIME LF HASHENTRY* EOF
156 // CACHELIFETIME = DIGIT+ 163 // CACHELIFETIME = DIGIT+
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 size_t hash_count; 223 size_t hash_count;
217 if (!base::StringToSizeT(hash_count_string, &hash_count)) 224 if (!base::StringToSizeT(hash_count_string, &hash_count))
218 return false; 225 return false;
219 226
220 if (hash_len * hash_count > reader.length()) 227 if (hash_len * hash_count > reader.length())
221 return false; 228 return false;
222 229
223 // Ignore hash results from lists we don't recognize. 230 // Ignore hash results from lists we don't recognize.
224 if (full_hash.list_id < 0) { 231 if (full_hash.list_id < 0) {
225 reader.Advance(hash_len * hash_count); 232 reader.Advance(hash_len * hash_count);
226 if (has_metadata && !ParseGetHashMetadata(hash_count, &reader)) 233 if (has_metadata && !ParseGetHashMetadata(hash_count, &reader, NULL))
227 return false; 234 return false;
228 continue; 235 continue;
229 } 236 }
230 237
231 for (size_t i = 0; i < hash_count; ++i) { 238 for (size_t i = 0; i < hash_count; ++i) {
232 if (!reader.GetData(&full_hash.hash, hash_len)) 239 if (!reader.GetData(&full_hash.hash, hash_len))
233 return false; 240 return false;
234 full_hashes->push_back(full_hash); 241 full_hashes->push_back(full_hash);
235 } 242 }
236 243
237 // Discard the metadata for now. 244 if (has_metadata && !ParseGetHashMetadata(hash_count, &reader, full_hashes))
238 // TODO(mattm): handle the metadata (see crbug.com/176648).
239 if (has_metadata && !ParseGetHashMetadata(hash_count, &reader))
240 return false; 245 return false;
241 } 246 }
242 247
243 return reader.empty(); 248 return reader.empty();
244 } 249 }
245 250
246 // BODY = HEADER LF PREFIXES EOF 251 // BODY = HEADER LF PREFIXES EOF
247 // HEADER = PREFIXSIZE ":" LENGTH 252 // HEADER = PREFIXSIZE ":" LENGTH
248 // PREFIXSIZE = DIGIT+ # Size of each prefix in bytes 253 // PREFIXSIZE = DIGIT+ # Size of each prefix in bytes
249 // LENGTH = DIGIT+ # Size of PREFIXES in bytes 254 // LENGTH = DIGIT+ # Size of PREFIXES in bytes
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (!list.adds.empty() && !list.subs.empty()) 387 if (!list.adds.empty() && !list.subs.empty())
383 formatted_results.append(":"); 388 formatted_results.append(":");
384 if (!list.subs.empty()) 389 if (!list.subs.empty())
385 formatted_results.append("s:").append(list.subs); 390 formatted_results.append("s:").append(list.subs);
386 formatted_results.append("\n"); 391 formatted_results.append("\n");
387 392
388 return formatted_results; 393 return formatted_results;
389 } 394 }
390 395
391 } // namespace safe_browsing 396 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/metadata.proto ('k') | chrome/browser/safe_browsing/protocol_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698