| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |