From 8d0fb607aa722d4a20371001f9a00d9ce28abde5 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 17 Jul 2018 17:48:26 +0200 Subject: [PATCH] Terminate IPs resolved externally as expected --- client/http_resolve_host.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/client/http_resolve_host.c b/client/http_resolve_host.c index 6a7a0dc5..37f86774 100644 --- a/client/http_resolve_host.c +++ b/client/http_resolve_host.c @@ -58,12 +58,12 @@ struct url static int try_url(struct url *url, fko_cli_options_t *options) { - int sock=-1, sock_success=0, res, error, http_buf_len; + int sock=-1, sock_success=0, i, res, error, http_buf_len; int bytes_read = 0, position = 0; struct addrinfo *result=NULL, *rp, hints; char http_buf[HTTP_MAX_REQUEST_LEN] = {0}; char http_response[HTTP_MAX_RESPONSE_LEN] = {0}; - char *ndx; + char *ndx, c; #ifdef WIN32 WSADATA wsa_data; @@ -196,10 +196,21 @@ try_url(struct url *url, fko_cli_options_t *options) } ndx += 4; - /* Try to parse the content as an IP address. - * Note: We are expecting the content to be exactly that - * (possibly followed by whitespace or other not-digit value). + /* Walk along the content to try to find the end of the IP address. + * Note: We are expecting the content to be just an IP address + * (possibly followed by whitespace or other not-digit value). + */ + for(i=0; i= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) && c != '.' && c != ':') + break; + } + + /* Terminate at the first non-digit and non-dot. */ + *(ndx+i) = '\0'; + + /* Try to parse the content as an IP address. */ memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ hints.ai_flags = AI_NUMERICHOST | AI_CANONNAME;