Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: net/dns/dns_util.cc

Issue 2739203003: Measure how often DNS hostnames aren't in preferred name form. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/dns/dns_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)) {
36 if (is_first_char) {
37 return false;
38 }
39 return c == '-' || c == '_';
40 }
41 return true;
42 }
43 }
Ryan Sleevi 2017/03/10 17:48:09 Newline between 42 & 43, plus a " //namespace" f
44
32 namespace net { 45 namespace net {
33 46
34 // Based on DJB's public domain code. 47 // Based on DJB's public domain code.
35 bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) { 48 bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) {
36 const char* buf = dotted.data(); 49 const char* buf = dotted.data();
37 unsigned n = dotted.size(); 50 size_t n = dotted.size();
38 char label[63]; 51 char label[63];
39 size_t labellen = 0; /* <= sizeof label */ 52 size_t labellen = 0; /* <= sizeof label */
40 char name[255]; 53 char name[255];
41 size_t namelen = 0; /* <= sizeof name */ 54 size_t namelen = 0; /* <= sizeof name */
42 char ch; 55 char ch;
43 56
44 for (;;) { 57 for (;;) {
45 if (!n) 58 if (!n)
46 break; 59 break;
47 ch = *buf++; 60 ch = *buf++;
48 --n; 61 --n;
49 if (ch == '.') { 62 if (ch == '.') {
50 // Don't allow empty labels per http://crbug.com/456391. 63 // Don't allow empty labels per http://crbug.com/456391.
51 if (!labellen) 64 if (!labellen)
52 return false; 65 return false;
53 if (namelen + labellen + 1 > sizeof name) 66 if (namelen + labellen + 1 > sizeof name)
54 return false; 67 return false;
55 name[namelen++] = static_cast<char>(labellen); 68 name[namelen++] = static_cast<char>(labellen);
56 memcpy(name + namelen, label, labellen); 69 memcpy(name + namelen, label, labellen);
57 namelen += labellen; 70 namelen += labellen;
58 labellen = 0; 71 labellen = 0;
59 continue; 72 continue;
60 } 73 }
61 if (labellen >= sizeof label) 74 if (labellen >= sizeof label)
62 return false; 75 return false;
76 if (!IsValidLabelCharacter(ch, labellen == 0))
77 return false;
63 label[labellen++] = ch; 78 label[labellen++] = ch;
64 } 79 }
65 80
66 // Allow empty label at end of name to disable suffix search. 81 // Allow empty label at end of name to disable suffix search.
67 if (labellen) { 82 if (labellen) {
68 if (namelen + labellen + 1 > sizeof name) 83 if (namelen + labellen + 1 > sizeof name)
69 return false; 84 return false;
70 name[namelen++] = static_cast<char>(labellen); 85 name[namelen++] = static_cast<char>(labellen);
71 memcpy(name + namelen, label, labellen); 86 memcpy(name + namelen, label, labellen);
72 namelen += labellen; 87 namelen += labellen;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return DELTA_IDENTICAL; 238 return DELTA_IDENTICAL;
224 else if (same_size && !any_missing) 239 else if (same_size && !any_missing)
225 return DELTA_REORDERED; 240 return DELTA_REORDERED;
226 else if (any_match) 241 else if (any_match)
227 return DELTA_OVERLAP; 242 return DELTA_OVERLAP;
228 else 243 else
229 return DELTA_DISJOINT; 244 return DELTA_DISJOINT;
230 } 245 }
231 246
232 } // namespace net 247 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/dns_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698