Skip to content

Commit

Permalink
url: reject ASCII control characters and space in host names
Browse files Browse the repository at this point in the history
Host names like "127.0.0.1 moo" would otherwise be accepted by some
getaddrinfo() implementations.

Fixes #2073
  • Loading branch information
bagder committed Nov 17, 2017
1 parent 715f1f5 commit c767b0f
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions lib/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ static bool is_ASCII_name(const char *hostname)
/*
* Perform any necessary IDN conversion of hostname
*/
static void fix_hostname(struct connectdata *conn, struct hostname *host)
static CURLcode fix_hostname(struct connectdata *conn, struct hostname *host)
{
size_t len;
struct Curl_easy *data = conn->data;
Expand Down Expand Up @@ -1746,6 +1746,16 @@ static void fix_hostname(struct connectdata *conn, struct hostname *host)
infof(data, "IDN support not present, can't parse Unicode domains\n");
#endif
}
{
char *hostp;
for(hostp = host->name; *hostp; hostp++) {
if(*hostp <= 32) {
failf(data, "Host name '%s' contains bad letter", host->name);
return CURLE_URL_MALFORMAT;
}
}
}
return CURLE_OK;
}

/*
Expand Down Expand Up @@ -4179,13 +4189,21 @@ static CURLcode create_conn(struct Curl_easy *data,
/*************************************************************
* IDN-fix the hostnames
*************************************************************/
fix_hostname(conn, &conn->host);
if(conn->bits.conn_to_host)
fix_hostname(conn, &conn->conn_to_host);
if(conn->bits.httpproxy)
fix_hostname(conn, &conn->http_proxy.host);
if(conn->bits.socksproxy)
fix_hostname(conn, &conn->socks_proxy.host);
result = fix_hostname(conn, &conn->host);
if(result)
goto out;
if(conn->bits.conn_to_host) {
result = fix_hostname(conn, &conn->conn_to_host);
goto out;
}
if(conn->bits.httpproxy) {
result = fix_hostname(conn, &conn->http_proxy.host);
goto out;
}
if(conn->bits.socksproxy) {
result = fix_hostname(conn, &conn->socks_proxy.host);
goto out;
}

/*************************************************************
* Check whether the host and the "connect to host" are equal.
Expand Down

0 comments on commit c767b0f

Please sign in to comment.