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

Unified Diff: net/dns/dns_util.cc

Issue 2739203003: Measure how often DNS hostnames aren't in preferred name form. (Closed)
Patch Set: We need to allow leading _. 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 | « no previous file | 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 217aedc50010252bde6c50459220751e0163f4c6..3b6ad0d9c048c3ae4482064ddbc2de51c957be9b 100644
--- a/net/dns/dns_util.cc
+++ b/net/dns/dns_util.cc
@@ -29,12 +29,26 @@
#include "net/android/network_library.h"
#endif
+namespace {
+
+bool IsValidLabelCharacter(char c, bool is_first_char) {
+ if (!isalnum(c) && c != '_') {
eroman 2017/03/14 16:07:49 Drive-by comment: isalnum() depends on the user's
+ if (is_first_char) {
+ return false;
+ }
+ return c == '-';
+ }
+ return true;
+}
+
+} // namespace
+
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[63];
size_t labellen = 0; /* <= sizeof label */
char name[255];
@@ -60,6 +74,8 @@ bool DNSDomainFromDot(const base::StringPiece& dotted, std::string* out) {
}
if (labellen >= sizeof label)
return false;
+ if (!IsValidLabelCharacter(ch, labellen == 0))
+ return false;
label[labellen++] = ch;
}
« 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