| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <Winsock2.h> // for htonl | 7 #include "build/build_config.h" |
| 8 |
| 9 #if defined(OS_WIN) |
| 10 #include <Winsock2.h> |
| 11 #elif defined(OS_POSIX) |
| 12 #include <arpa/inet.h> |
| 13 #endif |
| 8 | 14 |
| 9 #include "chrome/browser/safe_browsing/protocol_parser.h" | 15 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 10 | 16 |
| 11 #include "base/logging.h" | 17 #include "base/logging.h" |
| 12 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 13 | 19 |
| 14 namespace { | 20 namespace { |
| 15 // Helper function for quick scans of a line oriented protocol. Note that we use | 21 // Helper function for quick scans of a line oriented protocol. Note that we use |
| 16 // std::string::assign(const charT* s, size_type n) | 22 // std::string::assign(const charT* s, size_type n) |
| 17 // to copy data into 'line'. This form of 'assign' does not call strlen on | 23 // to copy data into 'line'. This form of 'assign' does not call strlen on |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 SplitString(line, ':', &cmd_parts); | 84 SplitString(line, ':', &cmd_parts); |
| 79 if (cmd_parts.size() != 3) | 85 if (cmd_parts.size() != 3) |
| 80 return false; | 86 return false; |
| 81 | 87 |
| 82 SBFullHashResult full_hash; | 88 SBFullHashResult full_hash; |
| 83 full_hash.list_name = cmd_parts[0]; | 89 full_hash.list_name = cmd_parts[0]; |
| 84 full_hash.add_chunk_id = atoi(cmd_parts[1].c_str()); | 90 full_hash.add_chunk_id = atoi(cmd_parts[1].c_str()); |
| 85 int full_hash_len = atoi(cmd_parts[2].c_str()); | 91 int full_hash_len = atoi(cmd_parts[2].c_str()); |
| 86 | 92 |
| 87 while (full_hash_len > 0) { | 93 while (full_hash_len > 0) { |
| 88 DCHECK(full_hash_len >= sizeof(SBFullHash)); | 94 DCHECK(static_cast<size_t>(full_hash_len) >= sizeof(SBFullHash)); |
| 89 memcpy(&full_hash.hash, data, sizeof(SBFullHash)); | 95 memcpy(&full_hash.hash, data, sizeof(SBFullHash)); |
| 90 full_hashes->push_back(full_hash); | 96 full_hashes->push_back(full_hash); |
| 91 data += sizeof(SBFullHash); | 97 data += sizeof(SBFullHash); |
| 92 length -= sizeof(SBFullHash); | 98 length -= sizeof(SBFullHash); |
| 93 full_hash_len -= sizeof(SBFullHash); | 99 full_hash_len -= sizeof(SBFullHash); |
| 94 } | 100 } |
| 95 } | 101 } |
| 96 | 102 |
| 97 return length == 0; | 103 return length == 0; |
| 98 } | 104 } |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 while (remaining > 0) { | 448 while (remaining > 0) { |
| 443 std::string line; | 449 std::string line; |
| 444 if (!GetLine(data, remaining, &line)) | 450 if (!GetLine(data, remaining, &line)) |
| 445 return false; | 451 return false; |
| 446 | 452 |
| 447 std::vector<std::string> cmd_parts; | 453 std::vector<std::string> cmd_parts; |
| 448 SplitString(line, ':', &cmd_parts); | 454 SplitString(line, ':', &cmd_parts); |
| 449 if (cmd_parts.size() != 3) | 455 if (cmd_parts.size() != 3) |
| 450 return false; | 456 return false; |
| 451 | 457 |
| 452 if (cmd_parts[2].size() != atoi(cmd_parts[1].c_str())) | 458 if (static_cast<int>(cmd_parts[2].size()) != atoi(cmd_parts[1].c_str())) |
| 453 return false; | 459 return false; |
| 454 | 460 |
| 455 if (cmd_parts[0] == "clientkey") { | 461 if (cmd_parts[0] == "clientkey") { |
| 456 client_key->assign(cmd_parts[2]); | 462 client_key->assign(cmd_parts[2]); |
| 457 } else if (cmd_parts[0] == "wrappedkey") { | 463 } else if (cmd_parts[0] == "wrappedkey") { |
| 458 wrapped_key->assign(cmd_parts[2]); | 464 wrapped_key->assign(cmd_parts[2]); |
| 459 } else { | 465 } else { |
| 460 return false; | 466 return false; |
| 461 } | 467 } |
| 462 | 468 |
| 463 data += line.size() + 1; | 469 data += line.size() + 1; |
| 464 remaining -= static_cast<int>(line.size()) + 1; | 470 remaining -= static_cast<int>(line.size()) + 1; |
| 465 } | 471 } |
| 466 | 472 |
| 467 if (client_key->empty() || wrapped_key->empty()) | 473 if (client_key->empty() || wrapped_key->empty()) |
| 468 return false; | 474 return false; |
| 469 | 475 |
| 470 return true; | 476 return true; |
| 471 } | 477 } |
| OLD | NEW |