From b504c854d34a938943f68c3036840f10a84fcea4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 28 Mar 2018 07:42:27 -0400 Subject: [PATCH] Rename string_is_valid_hostname -> string_is_valid_nonrfc_hostname Per discussion on 25055. --- src/common/util.c | 4 ++-- src/common/util.h | 2 +- src/test/test_util.c | 55 ++++++++++++++++++++++---------------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/common/util.c b/src/common/util.c index 5ae4d04082..90aaf0ebeb 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1094,7 +1094,7 @@ string_is_valid_dest(const char *string) retval = string_is_valid_ipv4_address(string) || string_is_valid_ipv6_address(string) || - string_is_valid_hostname(string); + string_is_valid_nonrfc_hostname(string); tor_free(tmp); @@ -1108,7 +1108,7 @@ string_is_valid_dest(const char *string) * with misconfigured zones that have been encountered in the wild. */ int -string_is_valid_hostname(const char *string) +string_is_valid_nonrfc_hostname(const char *string) { int result = 1; int has_trailing_dot; diff --git a/src/common/util.h b/src/common/util.h index d6bda80363..9380789128 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -234,7 +234,7 @@ const char *find_str_at_start_of_line(const char *haystack, int string_is_C_identifier(const char *string); int string_is_key_value(int severity, const char *string); int string_is_valid_dest(const char *string); -int string_is_valid_hostname(const char *string); +int string_is_valid_nonrfc_hostname(const char *string); int string_is_valid_ipv4_address(const char *string); int string_is_valid_ipv6_address(const char *string); diff --git a/src/test/test_util.c b/src/test/test_util.c index c734426a5a..036f739b89 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -5559,56 +5559,57 @@ test_util_hostname_validation(void *arg) (void)arg; // Lets try valid hostnames first. - tt_assert(string_is_valid_hostname("torproject.org")); - tt_assert(string_is_valid_hostname("ocw.mit.edu")); - tt_assert(string_is_valid_hostname("i.4cdn.org")); - tt_assert(string_is_valid_hostname("stanford.edu")); - tt_assert(string_is_valid_hostname("multiple-words-with-hypens.jp")); + tt_assert(string_is_valid_nonrfc_hostname("torproject.org")); + tt_assert(string_is_valid_nonrfc_hostname("ocw.mit.edu")); + tt_assert(string_is_valid_nonrfc_hostname("i.4cdn.org")); + tt_assert(string_is_valid_nonrfc_hostname("stanford.edu")); + tt_assert(string_is_valid_nonrfc_hostname("multiple-words-with-hypens.jp")); // Subdomain name cannot start with '-' or '_'. - tt_assert(!string_is_valid_hostname("-torproject.org")); - tt_assert(!string_is_valid_hostname("subdomain.-domain.org")); - tt_assert(!string_is_valid_hostname("-subdomain.domain.org")); - tt_assert(!string_is_valid_hostname("___abc.org")); + tt_assert(!string_is_valid_nonrfc_hostname("-torproject.org")); + tt_assert(!string_is_valid_nonrfc_hostname("subdomain.-domain.org")); + tt_assert(!string_is_valid_nonrfc_hostname("-subdomain.domain.org")); + tt_assert(!string_is_valid_nonrfc_hostname("___abc.org")); // Hostnames cannot contain non-alphanumeric characters. - tt_assert(!string_is_valid_hostname("%%domain.\\org.")); - tt_assert(!string_is_valid_hostname("***x.net")); - tt_assert(!string_is_valid_hostname("\xff\xffxyz.org")); - tt_assert(!string_is_valid_hostname("word1 word2.net")); + tt_assert(!string_is_valid_nonrfc_hostname("%%domain.\\org.")); + tt_assert(!string_is_valid_nonrfc_hostname("***x.net")); + tt_assert(!string_is_valid_nonrfc_hostname("\xff\xffxyz.org")); + tt_assert(!string_is_valid_nonrfc_hostname("word1 word2.net")); // Test workaround for nytimes.com stupidity, technically invalid, // but we allow it since they are big, even though they are failing to // comply with a ~30 year old standard. - tt_assert(string_is_valid_hostname("core3_euw1.fabrik.nytimes.com")); + tt_assert(string_is_valid_nonrfc_hostname("core3_euw1.fabrik.nytimes.com")); // Firefox passes FQDNs with trailing '.'s directly to the SOCKS proxy, // which is redundant since the spec states DOMAINNAME addresses are fully // qualified. While unusual, this should be tollerated. - tt_assert(string_is_valid_hostname("core9_euw1.fabrik.nytimes.com.")); - tt_assert(!string_is_valid_hostname("..washingtonpost.is.better.com")); - tt_assert(!string_is_valid_hostname("so.is..ft.com")); - tt_assert(!string_is_valid_hostname("...")); + tt_assert(string_is_valid_nonrfc_hostname("core9_euw1.fabrik.nytimes.com.")); + tt_assert(!string_is_valid_nonrfc_hostname( + "..washingtonpost.is.better.com")); + tt_assert(!string_is_valid_nonrfc_hostname("so.is..ft.com")); + tt_assert(!string_is_valid_nonrfc_hostname("...")); // XXX: do we allow single-label DNS names? // We shouldn't for SOCKS (spec says "contains a fully-qualified domain name" // but only test pathologically malformed traling '.' cases for now. - tt_assert(!string_is_valid_hostname(".")); - tt_assert(!string_is_valid_hostname("..")); + tt_assert(!string_is_valid_nonrfc_hostname(".")); + tt_assert(!string_is_valid_nonrfc_hostname("..")); // IP address strings are not hostnames. - tt_assert(!string_is_valid_hostname("8.8.8.8")); - tt_assert(!string_is_valid_hostname("[2a00:1450:401b:800::200e]")); - tt_assert(!string_is_valid_hostname("2a00:1450:401b:800::200e")); + tt_assert(!string_is_valid_nonrfc_hostname("8.8.8.8")); + tt_assert(!string_is_valid_nonrfc_hostname("[2a00:1450:401b:800::200e]")); + tt_assert(!string_is_valid_nonrfc_hostname("2a00:1450:401b:800::200e")); // We allow alphanumeric TLDs. For discussion, see ticket #25055. - tt_assert(string_is_valid_hostname("lucky.13")); - tt_assert(string_is_valid_hostname("luck.y13")); - tt_assert(string_is_valid_hostname("luck.y13.")); + tt_assert(string_is_valid_nonrfc_hostname("lucky.13")); + tt_assert(string_is_valid_nonrfc_hostname("luck.y13")); + tt_assert(string_is_valid_nonrfc_hostname("luck.y13.")); // We allow punycode TLDs. For examples, see // http://data.iana.org/TLD/tlds-alpha-by-domain.txt - tt_assert(string_is_valid_hostname("example.xn--l1acc")); + tt_assert(string_is_valid_nonrfc_hostname("example.xn--l1acc")); done: return;