1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

urlglob: treat literal IPv6 addresses with zone IDs as a host name

... and not as a "glob". Now done by passing the supposed host to the
URL parser which supposedly will do a better job at identifying "real"
numerical IPv6 addresses.

Reported-by: puckipedia on github
Fixes #5576
Closes #5579
This commit is contained in:
Daniel Stenberg 2020-06-18 13:27:59 +02:00
parent c888e3f6ce
commit fa4fbc533f
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -319,6 +319,8 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,
return CURLE_OK; return CURLE_OK;
} }
#define MAX_IP6LEN 128
static bool peek_ipv6(const char *str, size_t *skip) static bool peek_ipv6(const char *str, size_t *skip)
{ {
/* /*
@ -326,27 +328,32 @@ static bool peek_ipv6(const char *str, size_t *skip)
* - Valid globs contain a hyphen and <= 1 colon. * - Valid globs contain a hyphen and <= 1 colon.
* - IPv6 literals contain no hyphens and >= 2 colons. * - IPv6 literals contain no hyphens and >= 2 colons.
*/ */
size_t i = 0; char hostname[MAX_IP6LEN];
size_t colons = 0; CURLU *u;
if(str[i++] != '[') { char *endbr = strchr(str, ']');
size_t hlen;
CURLUcode rc;
if(!endbr)
return FALSE; return FALSE;
}
for(;;) { hlen = endbr - str + 1;
const char c = str[i++]; if(hlen >= MAX_IP6LEN)
if(ISALNUM(c) || c == '.' || c == '%') { return FALSE;
/* ok */
} u = curl_url();
else if(c == ':') { if(!u)
colons++; return FALSE;
}
else if(c == ']') { memcpy(hostname, str, hlen);
*skip = i; hostname[hlen] = 0;
return colons >= 2 ? TRUE : FALSE;
} /* ask to "guess scheme" as then it works without a https:// prefix */
else { rc = curl_url_set(u, CURLUPART_URL, hostname, CURLU_GUESS_SCHEME);
return FALSE;
} curl_url_cleanup(u);
} if(!rc)
*skip = hlen;
return rc ? FALSE : TRUE;
} }
static CURLcode glob_parse(struct URLGlob *glob, char *pattern, static CURLcode glob_parse(struct URLGlob *glob, char *pattern,