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

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

Issue 10216006: Use the correct remaining data length when parsing chunk headers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 bool SafeBrowsingProtocolParser::ParseChunk(const std::string& list_name, 193 bool SafeBrowsingProtocolParser::ParseChunk(const std::string& list_name,
194 const char* data, 194 const char* data,
195 int length, 195 int length,
196 SBChunkList* chunks) { 196 SBChunkList* chunks) {
197 int remaining = length; 197 int remaining = length;
198 const char* chunk_data = data; 198 const char* chunk_data = data;
199 199
200 while (remaining > 0) { 200 while (remaining > 0) {
201 std::string cmd_line; 201 std::string cmd_line;
202 if (!GetLine(chunk_data, length, &cmd_line)) 202 if (!GetLine(chunk_data, remaining, &cmd_line))
203 return false; // Error: bad chunk format! 203 return false; // Error: bad chunk format!
204 204
205 const int line_len = static_cast<int>(cmd_line.length()) + 1; 205 const int line_len = static_cast<int>(cmd_line.length()) + 1;
206 chunk_data += line_len; 206 chunk_data += line_len;
207 remaining -= line_len; 207 remaining -= line_len;
208 std::vector<std::string> cmd_parts; 208 std::vector<std::string> cmd_parts;
209 base::SplitString(cmd_line, ':', &cmd_parts); 209 base::SplitString(cmd_line, ':', &cmd_parts);
210 if (cmd_parts.size() != 4) { 210 if (cmd_parts.size() != 4) {
211 return false; 211 return false;
212 } 212 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 DCHECK_EQ(hash_len, (int)sizeof(SBFullHash)); 405 DCHECK_EQ(hash_len, (int)sizeof(SBFullHash));
406 entry->SetFullHashAt(i, *reinterpret_cast<const SBFullHash*>(*data)); 406 entry->SetFullHashAt(i, *reinterpret_cast<const SBFullHash*>(*data));
407 } 407 }
408 *data += hash_len; 408 *data += hash_len;
409 *remaining -= hash_len; 409 *remaining -= hash_len;
410 DCHECK_GE(*remaining, 0); 410 DCHECK_GE(*remaining, 0);
411 } 411 }
412 412
413 return true; 413 return true;
414 } 414 }
OLDNEW
« 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