From 539412851c4c81225c0a0f6d014b635a102b0a08 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 6 Mar 2014 00:06:45 +0000 Subject: parse_remote_port: error out on illegal port numbers better --- lib/url.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/url.c b/lib/url.c index 7a7c2781d..2240f1132 100644 --- a/lib/url.c +++ b/lib/url.c @@ -4770,24 +4770,21 @@ static CURLcode parse_remote_port(struct SessionHandle *data, /* no CURLOPT_PORT given, extract the one from the URL */ char *rest; - unsigned long port; + long port; - port=strtoul(portptr+1, &rest, 10); /* Port number must be decimal */ + port=strtol(portptr+1, &rest, 10); /* Port number must be decimal */ - if(rest != (portptr+1) && *rest == '\0') { - /* The colon really did have only digits after it, - * so it is either a port number or a mistake */ - - if(port > 0xffff) { /* Single unix standard says port numbers are - * 16 bits long */ - failf(data, "Port number too large: %lu", port); - return CURLE_URL_MALFORMAT; - } + if((port < 0) || (port > 0xffff)) { + /* Single unix standard says port numbers are 16 bits long */ + failf(data, "Port number out of range"); + return CURLE_URL_MALFORMAT; + } + else if(rest != &portptr[1]) { *portptr = '\0'; /* cut off the name there */ conn->remote_port = curlx_ultous(port); } - else if(!port) + else /* Browser behavior adaptation. If there's a colon with no digits after, just cut off the name there which makes us ignore the colon and just use the default port. Firefox and Chrome both do that. */ -- cgit v1.2.3