resolve: allow IP address within [] brackets

... so that IPv6 addresses can be passed like they can for connect-to
and how they're used in URLs.

Added test 1324 to verify
Reported-by: Alex Malinovich

Fixes #2087
Closes #2091
This commit is contained in:
Daniel Stenberg 2017-11-17 11:21:12 +01:00
parent 6ce9845677
commit 715f1f53e0
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 74 additions and 3 deletions

View file

@ -778,7 +778,6 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
{
struct curl_slist *hostp;
char hostname[256];
char address[256];
int port;
for(hostp = data->change.resolve; hostp; hostp = hostp->next) {
@ -820,6 +819,8 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
Curl_addrinfo *addr;
char *entry_id;
size_t entry_len;
char buffer[256];
char *address = &buffer[0];
if(3 != sscanf(hostp->data, "%255[^:]:%d:%255s", hostname, &port,
address)) {
@ -828,6 +829,16 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
continue;
}
/* allow IP(v6) address within [brackets] */
if(address[0] == '[') {
size_t alen = strlen(address);
if(address[alen-1] != ']')
/* it needs to also end with ] to be valid */
continue;
address[alen-1] = 0; /* zero terminate there */
address++; /* pass the open bracket */
}
addr = Curl_str2addr(address, port);
if(!addr) {
infof(data, "Address in '%s' found illegal!\n", hostp->data);