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

Unified Diff: net/dns/dns_util.cc

Issue 2739203003: Measure how often DNS hostnames aren't in preferred name form. (Closed)
Patch Set: Rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/dns_util.h ('k') | net/dns/dns_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_util.cc
diff --git a/net/dns/dns_util.cc b/net/dns/dns_util.cc
index 922390e6b57f0a8b2a05ec7b3621d3b0b938fb31..8eff1c6425eb204366eaf144b72e691b3f59c805 100644
--- a/net/dns/dns_util.cc
+++ b/net/dns/dns_util.cc
@@ -10,6 +10,7 @@
#include <cstring>
#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "build/build_config.h"
@@ -25,17 +26,32 @@ const int kMaxLabelLength = 63;
} // namespace
+#if defined(OS_POSIX)
+#include <netinet/in.h>
+#if !defined(OS_NACL)
+#include <net/if.h>
+#if !defined(OS_ANDROID)
+#include <ifaddrs.h>
+#endif // !defined(OS_ANDROID)
+#endif // !defined(OS_NACL)
+#endif // defined(OS_POSIX)
+
+#if defined(OS_ANDROID)
+#include "net/android/network_library.h"
+#endif
+
namespace net {
// Based on DJB's public domain code.
bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) {
const char* buf = dotted.data();
- unsigned n = dotted.size();
+ size_t n = dotted.size();
char label[kMaxLabelLength];
size_t labellen = 0; /* <= sizeof label */
char name[dns_protocol::kMaxNameLength];
size_t namelen = 0; /* <= sizeof name */
char ch;
+ bool valid_name = true;
for (;;) {
if (!n)
@@ -56,9 +72,16 @@ bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) {
}
if (labellen >= sizeof label)
return false;
+ if (!IsValidHostLabelCharacter(ch, labellen == 0)) {
+ // TODO(palmer): In the future, when we can remove support for invalid
+ // names, return false here instead (and remove the UMA counter).
+ valid_name = false;
+ }
label[labellen++] = ch;
}
+ UMA_HISTOGRAM_BOOLEAN("Net.ValidDNSName", valid_name);
+
// Allow empty label at end of name to disable suffix search.
if (labellen) {
if (namelen + labellen + 1 > sizeof name)
@@ -84,6 +107,11 @@ bool IsValidDNSDomain(const base::StringPiece& dotted) {
return DNSDomainFromDot(dotted, &dns_formatted);
}
+bool IsValidHostLabelCharacter(char c, bool is_first_char) {
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || (!is_first_char && c == '-') || c == '_';
+}
+
std::string DNSDomainToString(const base::StringPiece& domain) {
std::string ret;
« no previous file with comments | « net/dns/dns_util.h ('k') | net/dns/dns_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698