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
This commit is contained in:
Jens Finkhaeuser 2019-09-19 15:54:53 +02:00 committed by Daniel Stenberg
parent 346188f6e4
commit 0a4ecbdf1c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 57 additions and 11 deletions

View file

@ -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;
}
}
}