mirror of
https://github.com/curl/curl.git
synced 2026-08-12 14:20:54 +03:00
urlapi: consume trailing dots after IPv4 numerical addresses
If the hostname is specified as an IPv4 numerical address and it is followed by a single dot, acccept that as a valid IPv4 and remove the dot when normalizing. This prevents otherwise legitimate IPv4 hostnames to have trailing dots. Seems to match what browsers do. Extended test 1560 to verify. Closes #21635
This commit is contained in:
parent
aafbe089a8
commit
831a151484
3 changed files with 40 additions and 11 deletions
28
lib/urlapi.c
28
lib/urlapi.c
|
|
@ -496,6 +496,9 @@ static CURLUcode hostname_check(struct Curl_URL *u, char *hostname,
|
|||
* Output the "normalized" version of that input string in plain quad decimal
|
||||
* integers.
|
||||
*
|
||||
* A single dot following the numerical address is accepted and "swallowed" as
|
||||
* if it was never there.
|
||||
*
|
||||
* Returns the host type.
|
||||
*
|
||||
* @unittest 1675
|
||||
|
|
@ -527,17 +530,26 @@ UNITTEST int ipv4_normalize(struct dynbuf *host)
|
|||
else
|
||||
rc = curlx_str_number(&c, &l, UINT_MAX);
|
||||
|
||||
if(rc)
|
||||
return HOST_NAME;
|
||||
|
||||
parts[n] = (unsigned int)l;
|
||||
if(rc) {
|
||||
if(!n || (rc != STRE_NO_NUM) || *c)
|
||||
return HOST_NAME;
|
||||
n--;
|
||||
}
|
||||
else
|
||||
parts[n] = (unsigned int)l;
|
||||
|
||||
switch(*c) {
|
||||
case '.':
|
||||
if(n == 3)
|
||||
return HOST_NAME;
|
||||
n++;
|
||||
c++;
|
||||
if(n == 3) {
|
||||
if(c[1])
|
||||
/* something follows this dot */
|
||||
return HOST_NAME;
|
||||
done = TRUE;
|
||||
}
|
||||
else {
|
||||
n++;
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue