Handle IPv6 literals in URLs correctly
This commit is contained in:
parent
aa197d6dc8
commit
736e052dc1
15
src/reqs.c
15
src/reqs.c
@ -167,12 +167,18 @@ static void strip_username_password (char *host)
|
|||||||
static int strip_return_port (char *host)
|
static int strip_return_port (char *host)
|
||||||
{
|
{
|
||||||
char *ptr1;
|
char *ptr1;
|
||||||
|
char *ptr2;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
ptr1 = strchr (host, ':');
|
ptr1 = strrchr (host, ':');
|
||||||
if (ptr1 == NULL)
|
if (ptr1 == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* Check for IPv6 style literals */
|
||||||
|
ptr2 = strchr (ptr1, ']');
|
||||||
|
if (ptr2 != NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
*ptr1++ = '\0';
|
*ptr1++ = '\0';
|
||||||
if (sscanf (ptr1, "%d", &port) != 1) /* one conversion required */
|
if (sscanf (ptr1, "%d", &port) != 1) /* one conversion required */
|
||||||
return 0;
|
return 0;
|
||||||
@ -212,6 +218,13 @@ static int extract_http_url (const char *url, struct request_s *request)
|
|||||||
port = strip_return_port (request->host);
|
port = strip_return_port (request->host);
|
||||||
request->port = (port != 0) ? port : HTTP_PORT;
|
request->port = (port != 0) ? port : HTTP_PORT;
|
||||||
|
|
||||||
|
/* Remove any surrounding '[' and ']' from IPv6 literals */
|
||||||
|
p = strrchr (request->host, ']');
|
||||||
|
if (p && (*(request->host) == '[')) {
|
||||||
|
request->host++;
|
||||||
|
*p = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ERROR_EXIT:
|
ERROR_EXIT:
|
||||||
|
Loading…
Reference in New Issue
Block a user