hsts: ignore numberical IP address hosts

Also, use a single function library-wide for detecting if a given hostname is
a numerical IP address.

Reported-by: Harry Sintonen
Fixes #7146
Closes #7149
This commit is contained in:
Daniel Stenberg 2021-05-29 23:57:58 +02:00
parent 9097843e8f
commit 1c1d9f1aff
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 32 additions and 40 deletions

View file

@ -460,6 +460,25 @@ Curl_cache_addr(struct Curl_easy *data,
return dns;
}
/*
* Curl_host_is_ipnum() returns TRUE if the given string is a numerical IPv4
* (or IPv6 if supported) address.
*/
bool Curl_host_is_ipnum(const char *hostname)
{
struct in_addr in;
#ifdef ENABLE_IPV6
struct in6_addr in6;
#endif
if(Curl_inet_pton(AF_INET, hostname, &in) > 0
#ifdef ENABLE_IPV6
|| Curl_inet_pton(AF_INET6, hostname, &in6) > 0
#endif
)
return TRUE;
return FALSE;
}
/*
* Curl_resolv() is the main name resolve function within libcurl. It resolves
* a name and returns a pointer to the entry in the 'entry' argument (if one