From 9df8dc101ba03807a3257ba0922fe4dd03c81ed3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 4 Nov 2018 23:30:48 +0100 Subject: [PATCH] url: a short host name + port is not a scheme The function identifying a leading "scheme" part of the URL considered a few letters ending with a colon to be a scheme, making something like "short:80" to become an unknown scheme instead of a short host name and a port number. Extended test 1560 to verify. Also fixed test203 to use file_pwd to make it get the correct path on windows. Removed test 2070 since it was a duplicate of 203. Assisted-by: Marcel Raad Reported-by: Hagai Auro Fixes #3220 Fixes #3233 Closes #3223 Closes #3235 --- lib/url.c | 4 +++- lib/urlapi.c | 2 +- tests/FILEFORMAT | 2 ++ tests/data/Makefile.inc | 2 +- tests/data/test203 | 6 +++++- tests/data/test2070 | 41 ----------------------------------------- tests/libtest/lib1560.c | 14 ++++++++++++++ tests/runtests.pl | 7 +++++++ 8 files changed, 33 insertions(+), 45 deletions(-) delete mode 100644 tests/data/test2070 diff --git a/lib/url.c b/lib/url.c index 121920c76..dd9fa2617 100644 --- a/lib/url.c +++ b/lib/url.c @@ -2049,8 +2049,10 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, (data->set.disallow_username_in_url ? CURLU_DISALLOW_USER : 0) | (data->set.path_as_is ? CURLU_PATH_AS_IS : 0)); - if(uc) + if(uc) { + DEBUGF(infof(data, "curl_url_set rejected %s\n", data->change.url)); return Curl_uc_to_curlcode(uc); + } uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0); if(uc) diff --git a/lib/urlapi.c b/lib/urlapi.c index 18a6076ff..e877dc726 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -238,7 +238,7 @@ bool Curl_is_absolute_url(const char *url, char *buf, size_t buflen) #endif for(i = 0; i < buflen && url[i]; ++i) { char s = url[i]; - if(s == ':') { + if((s == ':') && (url[i + 1] == '/')) { if(buf) buf[i] = 0; return TRUE; diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT index d2bcc4e00..505c573cb 100644 --- a/tests/FILEFORMAT +++ b/tests/FILEFORMAT @@ -365,6 +365,8 @@ Available substitute variables include: %POP3PORT - Port number of the POP3 server %PROXYPORT - Port number of the HTTP proxy %PWD - Current directory +%POSIX_PWD - Current directory somewhat mingw friendly +%FILE_PWD - Current directory, on windows prefixed with a slash %RTSP6PORT - IPv6 port number of the RTSP server %RTSPPORT - Port number of the RTSP server %SMTP6PORT - IPv6 port number of the SMTP server diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 4611d3cb8..a4fe1deff 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -201,7 +201,7 @@ test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 \ test2048 test2049 test2050 test2051 test2052 test2053 test2054 test2055 \ test2056 test2057 test2058 test2059 test2060 test2061 test2062 test2063 \ test2064 test2065 test2066 test2067 test2068 test2069 \ -test2070 test2071 test2072 test2073 test2074 test2075 \ + test2071 test2072 test2073 test2074 test2075 \ test2080 \ test2100 \ \ diff --git a/tests/data/test203 b/tests/data/test203 index 393842656..ee850cb1c 100644 --- a/tests/data/test203 +++ b/tests/data/test203 @@ -24,8 +24,12 @@ file file:/path URL with a single slash + +# Needed for MSYS2 to not convert +MSYS2_ARG_CONV_EXCL=file: + -file:%PWD/log/test203.txt +file:%FILE_PWD/log/test203.txt foo diff --git a/tests/data/test2070 b/tests/data/test2070 deleted file mode 100644 index 655cd8a39..000000000 --- a/tests/data/test2070 +++ /dev/null @@ -1,41 +0,0 @@ - - - -FILE - - - - - -foo - bar -bar - foo -moo - - - -# Client-side - - -file - - -basic file:// file with no authority - - -file:%PWD/log/test2070.txt - - -foo - bar -bar - foo -moo - - - -# Verify data after the test has been "shot" - - - diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index 57469a906..5aa6f4bbc 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -128,6 +128,20 @@ struct querycase { }; static struct testcase get_parts_list[] ={ +#ifdef WIN32 + {"file:/C:\\programs\\foo", + "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"file://C:\\programs\\foo", + "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"file:///C:\\programs\\foo", + "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, +#endif + {"boing:80", + "https | [11] | [12] | [13] | boing | 80 | / | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, {"http://[fd00:a41::50]:8080", "http | [11] | [12] | [13] | [fd00:a41::50] | 8080 | / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, diff --git a/tests/runtests.pl b/tests/runtests.pl index 421cf2a6b..5b51d3e4f 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -3113,6 +3113,13 @@ sub subVariables { $$thing =~ s/%CURL/$CURL/g; $$thing =~ s/%PWD/$pwd/g; $$thing =~ s/%POSIX_PWD/$posix_pwd/g; + + my $file_pwd = $pwd; + if($file_pwd !~ /^\//) { + $file_pwd = "/$file_pwd"; + } + + $$thing =~ s/%FILE_PWD/$file_pwd/g; $$thing =~ s/%SRCDIR/$srcdir/g; $$thing =~ s/%USER/$USER/g;