Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "net/dns/dns_util.h" | 5 #include "net/dns/dns_util.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 | 9 |
| 10 #include <cstring> | 10 #include <cstring> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #endif // defined(OS_POSIX) | 26 #endif // defined(OS_POSIX) |
| 27 | 27 |
| 28 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 29 #include "net/android/network_library.h" | 29 #include "net/android/network_library.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace net { | 32 namespace net { |
| 33 | 33 |
| 34 // Based on DJB's public domain code. | 34 // Based on DJB's public domain code. |
| 35 bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) { | 35 bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) { |
| 36 // Refuse to convert invalid host names. | |
|
Julia Tuttle
2016/09/09 20:24:38
This is commented out; remove it?
mmenke
2016/09/09 20:38:44
Oops, thanks! I hadn't realized this was actually
| |
| 37 // if (!IsHostnameValid(dotted)) | |
| 38 // return false; | |
| 39 | |
| 36 const char* buf = dotted.data(); | 40 const char* buf = dotted.data(); |
| 37 unsigned n = dotted.size(); | 41 unsigned n = dotted.size(); |
| 38 char label[63]; | 42 char label[63]; |
| 39 size_t labellen = 0; /* <= sizeof label */ | 43 size_t labellen = 0; /* <= sizeof label */ |
| 40 char name[255]; | 44 char name[255]; |
| 41 size_t namelen = 0; /* <= sizeof name */ | 45 size_t namelen = 0; /* <= sizeof name */ |
| 42 char ch; | 46 char ch; |
| 43 | 47 |
| 44 for (;;) { | 48 for (;;) { |
| 45 if (!n) | 49 if (!n) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 76 if (namelen + 1 > sizeof name) | 80 if (namelen + 1 > sizeof name) |
| 77 return false; | 81 return false; |
| 78 if (namelen == 0) // Empty names e.g. "", "." are not valid. | 82 if (namelen == 0) // Empty names e.g. "", "." are not valid. |
| 79 return false; | 83 return false; |
| 80 name[namelen++] = 0; // This is the root label (of length 0). | 84 name[namelen++] = 0; // This is the root label (of length 0). |
| 81 | 85 |
| 82 *out = std::string(name, namelen); | 86 *out = std::string(name, namelen); |
| 83 return true; | 87 return true; |
| 84 } | 88 } |
| 85 | 89 |
| 90 bool IsValidDNSDomain(const base::StringPiece& dotted) { | |
| 91 std::string dns_formatted; | |
| 92 return DNSDomainFromDot(dotted, &dns_formatted); | |
| 93 } | |
| 94 | |
| 86 std::string DNSDomainToString(const base::StringPiece& domain) { | 95 std::string DNSDomainToString(const base::StringPiece& domain) { |
| 87 std::string ret; | 96 std::string ret; |
| 88 | 97 |
| 89 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) { | 98 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) { |
| 90 #if CHAR_MIN < 0 | 99 #if CHAR_MIN < 0 |
| 91 if (domain[i] < 0) | 100 if (domain[i] < 0) |
| 92 return std::string(); | 101 return std::string(); |
| 93 #endif | 102 #endif |
| 94 if (domain[i] > 63) | 103 if (domain[i] > 63) |
| 95 return std::string(); | 104 return std::string(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 return DELTA_IDENTICAL; | 227 return DELTA_IDENTICAL; |
| 219 else if (same_size && !any_missing) | 228 else if (same_size && !any_missing) |
| 220 return DELTA_REORDERED; | 229 return DELTA_REORDERED; |
| 221 else if (any_match) | 230 else if (any_match) |
| 222 return DELTA_OVERLAP; | 231 return DELTA_OVERLAP; |
| 223 else | 232 else |
| 224 return DELTA_DISJOINT; | 233 return DELTA_DISJOINT; |
| 225 } | 234 } |
| 226 | 235 |
| 227 } // namespace net | 236 } // namespace net |
| OLD | NEW |