summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJens Finkhaeuser <jens@finkhaeuser.de>2019-09-19 15:54:53 +0200
committerDaniel Stenberg <daniel@haxx.se>2019-09-19 15:57:28 +0200
commit0a4ecbdf1c35de3a0a367db73edbf50fabc0fb0e (patch)
tree6683941b25029f617b35d5ca9787391680bdb3c9 /lib
parent346188f6e455ab99f1d040e3ba474b80e9694bda (diff)
downloadcurl-0a4ecbdf1c35de3a0a367db73edbf50fabc0fb0e.tar.gz
urlapi: CURLU_NO_AUTHORITY allows empty authority/host part
CURLU_NO_AUTHORITY is intended for use with unknown schemes (i.e. not "file:///") to override cURL's default demand that an authority exists. Closes #4349
Diffstat (limited to 'lib')
-rw-r--r--lib/urlapi.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/urlapi.c b/lib/urlapi.c
index a0ee331da..6e414cf18 100644
--- a/lib/urlapi.c
+++ b/lib/urlapi.c
@@ -784,6 +784,7 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
if(junkscan(schemep))
return CURLUE_MALFORMED_INPUT;
+
}
else {
/* no scheme! */
@@ -804,11 +805,14 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
p++;
len = p - hostp;
- if(!len)
- return CURLUE_MALFORMED_INPUT;
-
- memcpy(hostname, hostp, len);
- hostname[len] = 0;
+ if(len) {
+ memcpy(hostname, hostp, len);
+ hostname[len] = 0;
+ }
+ else {
+ if(!(flags & CURLU_NO_AUTHORITY))
+ return CURLUE_MALFORMED_INPUT;
+ }
if((flags & CURLU_GUESS_SCHEME) && !schemep) {
/* legacy curl-style guess based on host name */
@@ -889,9 +893,14 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
if(result)
return result;
- result = hostname_check(u, hostname);
- if(result)
- return result;
+ if(0 == strlen(hostname) && (flags & CURLU_NO_AUTHORITY)) {
+ /* Skip hostname check, it's allowed to be empty. */
+ }
+ else {
+ result = hostname_check(u, hostname);
+ if(result)
+ return result;
+ }
u->host = strdup(hostname);
if(!u->host)
@@ -1432,9 +1441,14 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
}
if(what == CURLUPART_HOST) {
- if(hostname_check(u, (char *)newp)) {
- free((char *)newp);
- return CURLUE_MALFORMED_INPUT;
+ if(0 == strlen(newp) && (flags & CURLU_NO_AUTHORITY)) {
+ /* Skip hostname check, it's allowed to be empty. */
+ }
+ else {
+ if(hostname_check(u, (char *)newp)) {
+ free((char *)newp);
+ return CURLUE_MALFORMED_INPUT;
+ }
}
}