| 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/base/dns_util.h" | 5 #include "net/base/dns_util.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 name[namelen++] = 0; // This is the root label (of length 0). | 53 name[namelen++] = 0; // This is the root label (of length 0). |
| 54 | 54 |
| 55 *out = std::string(name, namelen); | 55 *out = std::string(name, namelen); |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 std::string DNSDomainToString(const std::string& domain) { | 59 std::string DNSDomainToString(const std::string& domain) { |
| 60 std::string ret; | 60 std::string ret; |
| 61 | 61 |
| 62 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) { | 62 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) { |
| 63 if (domain[i] < 0 || domain[i] > 63) | 63 #if CHAR_MIN < 0 |
| 64 if (domain[i] < 0) |
| 65 return ""; |
| 66 #endif |
| 67 if (domain[i] > 63) |
| 64 return ""; | 68 return ""; |
| 65 | 69 |
| 66 if (i) | 70 if (i) |
| 67 ret += "."; | 71 ret += "."; |
| 68 | 72 |
| 69 if (static_cast<unsigned>(domain[i]) + i + 1 > domain.size()) | 73 if (static_cast<unsigned>(domain[i]) + i + 1 > domain.size()) |
| 70 return ""; | 74 return ""; |
| 71 | 75 |
| 72 ret += domain.substr(i + 1, domain[i]); | 76 ret += domain.substr(i + 1, domain[i]); |
| 73 } | 77 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 break; | 210 break; |
| 207 } else { | 211 } else { |
| 208 return false; | 212 return false; |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 return true; | 216 return true; |
| 213 } | 217 } |
| 214 | 218 |
| 215 } // namespace net | 219 } // namespace net |
| OLD | NEW |