@@ -58,12 +58,12 @@ struct url
58
58
static int
59
59
try_url (struct url * url , fko_cli_options_t * options )
60
60
{
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 ;
62
62
int bytes_read = 0 , position = 0 ;
63
63
struct addrinfo * result = NULL , * rp , hints ;
64
64
char http_buf [HTTP_MAX_REQUEST_LEN ] = {0 };
65
65
char http_response [HTTP_MAX_RESPONSE_LEN ] = {0 };
66
- char * ndx ;
66
+ char * ndx , c ;
67
67
68
68
#ifdef WIN32
69
69
WSADATA wsa_data ;
@@ -196,10 +196,21 @@ try_url(struct url *url, fko_cli_options_t *options)
196
196
}
197
197
ndx += 4 ;
198
198
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.
202
210
*/
211
+ * (ndx + i ) = '\0' ;
212
+
213
+ /* Try to parse the content as an IP address. */
203
214
memset (& hints , 0 , sizeof (struct addrinfo ));
204
215
hints .ai_family = AF_UNSPEC ; /* Allow IPv4 or IPv6 */
205
216
hints .ai_flags = AI_NUMERICHOST | AI_CANONNAME ;
0 commit comments