Skip to content

Commit 8d0fb60

Browse files
committed
Terminate IPs resolved externally as expected
1 parent 3d4b153 commit 8d0fb60

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

client/http_resolve_host.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ struct url
5858
static int
5959
try_url(struct url *url, fko_cli_options_t *options)
6060
{
61-
int sock=-1, sock_success=0, res, error, http_buf_len;
61+
int sock=-1, sock_success=0, i, res, error, http_buf_len;
6262
int bytes_read = 0, position = 0;
6363
struct addrinfo *result=NULL, *rp, hints;
6464
char http_buf[HTTP_MAX_REQUEST_LEN] = {0};
6565
char http_response[HTTP_MAX_RESPONSE_LEN] = {0};
66-
char *ndx;
66+
char *ndx, c;
6767

6868
#ifdef WIN32
6969
WSADATA wsa_data;
@@ -196,10 +196,21 @@ try_url(struct url *url, fko_cli_options_t *options)
196196
}
197197
ndx += 4;
198198

199-
/* Try to parse the content as an IP address.
200-
* Note: We are expecting the content to be exactly that
201-
* (possibly followed by whitespace or other not-digit value).
199+
/* Walk along the content to try to find the end of the IP address.
200+
* Note: We are expecting the content to be just an IP address
201+
* (possibly followed by whitespace or other not-digit value).
202+
*/
203+
for(i=0; i<MAX_IPV46_STR_LEN; i++) {
204+
c = *(ndx+i);
205+
if(! isdigit((int)(unsigned char)c) && ! ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) && c != '.' && c != ':')
206+
break;
207+
}
208+
209+
/* Terminate at the first non-digit and non-dot.
202210
*/
211+
*(ndx+i) = '\0';
212+
213+
/* Try to parse the content as an IP address. */
203214
memset(&hints, 0, sizeof(struct addrinfo));
204215
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
205216
hints.ai_flags = AI_NUMERICHOST | AI_CANONNAME;

0 commit comments

Comments
 (0)