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 11 matching lines...) Expand all Loading... | |
| 22 #if !defined(OS_ANDROID) | 22 #if !defined(OS_ANDROID) | 
| 23 #include <ifaddrs.h> | 23 #include <ifaddrs.h> | 
| 24 #endif // !defined(OS_ANDROID) | 24 #endif // !defined(OS_ANDROID) | 
| 25 #endif // !defined(OS_NACL) | 25 #endif // !defined(OS_NACL) | 
| 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 { | |
| 33 | |
| 34 bool IsValidLabelCharacter(char c, bool is_first_char) { | |
| 35 if (!isalnum(c) && c != '_') { | |
| 
 
eroman
2017/03/14 16:07:49
Drive-by comment: isalnum() depends on the user's
 
 | |
| 36 if (is_first_char) { | |
| 37 return false; | |
| 38 } | |
| 39 return c == '-'; | |
| 40 } | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 32 namespace net { | 46 namespace net { | 
| 33 | 47 | 
| 34 // Based on DJB's public domain code. | 48 // Based on DJB's public domain code. | 
| 35 bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) { | 49 bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) { | 
| 36 const char* buf = dotted.data(); | 50 const char* buf = dotted.data(); | 
| 37 unsigned n = dotted.size(); | 51 size_t n = dotted.size(); | 
| 38 char label[63]; | 52 char label[63]; | 
| 39 size_t labellen = 0; /* <= sizeof label */ | 53 size_t labellen = 0; /* <= sizeof label */ | 
| 40 char name[255]; | 54 char name[255]; | 
| 41 size_t namelen = 0; /* <= sizeof name */ | 55 size_t namelen = 0; /* <= sizeof name */ | 
| 42 char ch; | 56 char ch; | 
| 43 | 57 | 
| 44 for (;;) { | 58 for (;;) { | 
| 45 if (!n) | 59 if (!n) | 
| 46 break; | 60 break; | 
| 47 ch = *buf++; | 61 ch = *buf++; | 
| 48 --n; | 62 --n; | 
| 49 if (ch == '.') { | 63 if (ch == '.') { | 
| 50 // Don't allow empty labels per http://crbug.com/456391. | 64 // Don't allow empty labels per http://crbug.com/456391. | 
| 51 if (!labellen) | 65 if (!labellen) | 
| 52 return false; | 66 return false; | 
| 53 if (namelen + labellen + 1 > sizeof name) | 67 if (namelen + labellen + 1 > sizeof name) | 
| 54 return false; | 68 return false; | 
| 55 name[namelen++] = static_cast<char>(labellen); | 69 name[namelen++] = static_cast<char>(labellen); | 
| 56 memcpy(name + namelen, label, labellen); | 70 memcpy(name + namelen, label, labellen); | 
| 57 namelen += labellen; | 71 namelen += labellen; | 
| 58 labellen = 0; | 72 labellen = 0; | 
| 59 continue; | 73 continue; | 
| 60 } | 74 } | 
| 61 if (labellen >= sizeof label) | 75 if (labellen >= sizeof label) | 
| 62 return false; | 76 return false; | 
| 77 if (!IsValidLabelCharacter(ch, labellen == 0)) | |
| 78 return false; | |
| 63 label[labellen++] = ch; | 79 label[labellen++] = ch; | 
| 64 } | 80 } | 
| 65 | 81 | 
| 66 // Allow empty label at end of name to disable suffix search. | 82 // Allow empty label at end of name to disable suffix search. | 
| 67 if (labellen) { | 83 if (labellen) { | 
| 68 if (namelen + labellen + 1 > sizeof name) | 84 if (namelen + labellen + 1 > sizeof name) | 
| 69 return false; | 85 return false; | 
| 70 name[namelen++] = static_cast<char>(labellen); | 86 name[namelen++] = static_cast<char>(labellen); | 
| 71 memcpy(name + namelen, label, labellen); | 87 memcpy(name + namelen, label, labellen); | 
| 72 namelen += labellen; | 88 namelen += labellen; | 
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 return DELTA_IDENTICAL; | 239 return DELTA_IDENTICAL; | 
| 224 else if (same_size && !any_missing) | 240 else if (same_size && !any_missing) | 
| 225 return DELTA_REORDERED; | 241 return DELTA_REORDERED; | 
| 226 else if (any_match) | 242 else if (any_match) | 
| 227 return DELTA_OVERLAP; | 243 return DELTA_OVERLAP; | 
| 228 else | 244 else | 
| 229 return DELTA_DISJOINT; | 245 return DELTA_DISJOINT; | 
| 230 } | 246 } | 
| 231 | 247 | 
| 232 } // namespace net | 248 } // namespace net | 
| OLD | NEW |