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

@ -36,7 +36,7 @@
#include "hostcheck.h"
#include "strcase.h"
#include "inet_pton.h"
#include "hostip.h"
#include "curl_memory.h"
/* The last #include file should be: */
@ -67,10 +67,6 @@ static int hostmatch(char *hostname, char *pattern)
const char *pattern_label_end, *pattern_wildcard, *hostname_label_end;
int wildcard_enabled;
size_t prefixlen, suffixlen;
struct in_addr ignored;
#ifdef ENABLE_IPV6
struct sockaddr_in6 si6;
#endif
/* normalize pattern and hostname by stripping off trailing dots */
size_t len = strlen(hostname);
@ -86,12 +82,8 @@ static int hostmatch(char *hostname, char *pattern)
CURL_HOST_MATCH : CURL_HOST_NOMATCH;
/* detect IP address as hostname and fail the match if so */
if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0)
if(Curl_host_is_ipnum(hostname))
return CURL_HOST_NOMATCH;
#ifdef ENABLE_IPV6
if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0)
return CURL_HOST_NOMATCH;
#endif
/* We require at least 2 dots in pattern to avoid too wide wildcard
match. */