Rename string_is_valid_hostname -> string_is_valid_nonrfc_hostname

Per discussion on 25055.
This commit is contained in:
Nick Mathewson 2018-03-28 07:42:27 -04:00
parent 09351c34e9
commit b504c854d3
3 changed files with 31 additions and 30 deletions

View File

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

View File

@ -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);

View File

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