diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2017-03-06 16:08:21 +0100 | 
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2017-03-06 16:08:21 +0100 | 
| commit | aadb7c7b62251c4e760930d543105f2b10cbd9b2 (patch) | |
| tree | d11600c715804a7d85c6005e2d121d000168f245 /lib | |
| parent | 7ad72e0fc274b85130a75003fcb49c59c49d3dd7 (diff) | |
URL: return error on malformed URLs with junk after port number
... because it causes confusion with users. Example URLs:
"http://[127.0.0.1]:11211:80" which a lot of languages' URL parsers will
parse and claim uses port number 80, while libcurl would use port number
11211.
"http://user@example.com:80@localhost" which by the WHATWG URL spec will
be treated to contain user name 'user@example.com' but according to
RFC3986 is user name 'user' for the host 'example.com' and then port 80
is followed by "@localhost"
Both these formats are now rejected, and verified so in test 1260.
Reported-by: Orange Tsai
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/url.c | 13 | 
1 files changed, 7 insertions, 6 deletions
| @@ -5643,7 +5643,7 @@ static CURLcode parse_remote_port(struct Curl_easy *data,      }  #endif -    portptr = strrchr(conn->host.name, ':'); +    portptr = strchr(conn->host.name, ':');    }    if(data->set.use_port && data->state.allow_port) { @@ -5698,15 +5698,16 @@ static CURLcode parse_remote_port(struct Curl_easy *data,        return CURLE_URL_MALFORMAT;      } -    else if(rest != &portptr[1]) { +    if(rest[0]) { +      failf(data, "Port number ended with '%c'", rest[0]); +      return CURLE_URL_MALFORMAT; +    } + +    if(rest != &portptr[1]) {        *portptr = '\0'; /* cut off the name there */        conn->remote_port = curlx_ultous(port);      }      else { -      if(rest[0]) { -        failf(data, "Illegal port number"); -        return CURLE_URL_MALFORMAT; -      }        /* 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. */ | 
