diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-02-19 21:08:51 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-03-28 07:39:03 -0400 |
commit | ee1fca727cd739ba94c215a4a45a416bfcc8956e (patch) | |
tree | 2ca5f0947cfdeac307c609707571339f8e6b1491 /src/common | |
parent | dbb7c8e6fd757db51226a47a2e14f4fd1aaf60c3 (diff) | |
download | tor-ee1fca727cd739ba94c215a4a45a416bfcc8956e.tar.gz tor-ee1fca727cd739ba94c215a4a45a416bfcc8956e.zip |
Simplify hostname validation code
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/common/util.c b/src/common/util.c index a55f7a3cd5..1402462fb0 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1113,6 +1113,9 @@ string_is_valid_hostname(const char *string) if (!string || strlen(string) == 0) return 0; + if (string_is_valid_ipv4_address(string)) + return 0; + components = smartlist_new(); smartlist_split_string(components,string,".",0,0); @@ -1134,25 +1137,10 @@ string_is_valid_hostname(const char *string) break; } - if (c_sl_idx == c_sl_len - 1) { // TLD validation. - int is_punycode = (strlen(c) > 4 && - (c[0] == 'X' || c[0] == 'x') && - (c[1] == 'N' || c[1] == 'n') && - c[2] == '-' && c[3] == '-'); - - if (is_punycode) - c += 4; - - do { - result = is_punycode ? TOR_ISALNUM(*c) : TOR_ISALPHA(*c); - c++; - } while (result && *c); - } else { // Regular hostname label validation. - do { - result = (TOR_ISALNUM(*c) || (*c == '-') || (*c == '_')); - c++; - } while (result > 0 && *c); - } + do { + result = (TOR_ISALNUM(*c) || (*c == '-') || (*c == '_')); + c++; + } while (result > 0 && *c); if (result == 0) { break; |