From f0d6cc23ae53ce7e51bdb56ad03a2f9fd3aae2df Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Wed, 6 Oct 2004 18:40:10 +0000 Subject: [PATCH] USE_LIBIDN: Added Top-level-domain (TLD) check for host->name. Only print a warning if check fails. --- lib/url.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/url.c b/lib/url.c index 07d85fd..e83836e 100644 --- a/lib/url.c +++ b/lib/url.c @@ -86,6 +86,7 @@ #ifdef USE_LIBIDN #include +#include #include #ifdef HAVE_IDN_FREE_H #include @@ -2075,6 +2076,36 @@ static bool is_ASCII_name (const char *hostname) } return TRUE; } + +/* + * Check if characters in hostname is allowed in Top Level Domain. + */ +static bool tld_check_name (struct connectdata *conn, + const char *ace_hostname) +{ + struct SessionHandle *data = conn->data; + size_t err_pos; + char *uc_name = NULL; + int rc; + + /* Convert (and downcase) ACE-name back into locale's character set */ + rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0); + if (rc != IDNA_SUCCESS) + infof(data, "Failed to convert %s from ACE; %s\n", + ace_hostname, Curl_idn_strerror(conn,rc)); + + rc = tld_check_lz(uc_name, &err_pos, NULL); + if (rc == TLD_INVALID) + infof(data, "WARNING: %s; pos %u = `%c'/0x%02X\n", + tld_strerror(rc), err_pos, uc_name[err_pos], + uc_name[err_pos] & 255); + else if (rc != TLD_SUCCESS) + infof(data, "WARNING: TLD check for %s failed; %s\n", + uc_name, tld_strerror(rc)); + if (uc_name) + idn_free(uc_name); + return (rc == TLD_SUCCESS); +} #endif static void fix_hostname(struct connectdata *conn, struct hostname *host) @@ -2097,6 +2128,8 @@ static void fix_hostname(struct connectdata *conn, struct hostname *host) infof(data, "Failed to convert %s to ACE; %s\n", host->name, Curl_idn_strerror(conn,rc)); else { + tld_check_name(conn, ace_hostname); + host->encalloc = ace_hostname; /* change the name pointer to point to the encoded hostname */ host->name = host->encalloc; -- 2.7.4