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; |
} |