mirror of
https://github.com/curl/curl.git
synced 2026-07-24 10:57:16 +03:00
curl_url_set: reject spaces in URLs w/o CURLU_ALLOW_SPACE
They were never officially allowed and slipped in only due to sloppy parsing. Spaces (ascii 32) should be correctly encoded (to %20) before being part of a URL. The new flag bit CURLU_ALLOW_SPACE when a full URL is set, makes libcurl allow spaces. Updated test 1560 to verify. Closes #7073
This commit is contained in:
parent
8f717b6cf0
commit
b67d3ba73e
8 changed files with 60 additions and 19 deletions
|
|
@ -1639,7 +1639,8 @@ CURLcode Curl_follow(struct Curl_easy *data,
|
|||
DEBUGASSERT(data->state.uh);
|
||||
uc = curl_url_set(data->state.uh, CURLUPART_URL, newurl,
|
||||
(type == FOLLOW_FAKE) ? CURLU_NON_SUPPORT_SCHEME :
|
||||
((type == FOLLOW_REDIR) ? CURLU_URLENCODE : 0) );
|
||||
((type == FOLLOW_REDIR) ? CURLU_URLENCODE : 0) |
|
||||
CURLU_ALLOW_SPACE);
|
||||
if(uc) {
|
||||
if(type != FOLLOW_FAKE)
|
||||
return Curl_uc_to_curlcode(uc);
|
||||
|
|
|
|||
20
lib/urlapi.c
20
lib/urlapi.c
|
|
@ -131,7 +131,7 @@ static const char *find_host_sep(const char *url)
|
|||
*/
|
||||
static bool urlchar_needs_escaping(int c)
|
||||
{
|
||||
return !(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c));
|
||||
return !(ISCNTRL(c) || ISSPACE(c) || ISGRAPH(c));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -580,7 +580,7 @@ UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, char *hostname,
|
|||
}
|
||||
|
||||
/* scan for byte values < 31 or 127 */
|
||||
static CURLUcode junkscan(const char *part)
|
||||
static bool junkscan(const char *part, unsigned int flags)
|
||||
{
|
||||
if(part) {
|
||||
static const char badbytes[]={
|
||||
|
|
@ -588,17 +588,18 @@ static CURLUcode junkscan(const char *part)
|
|||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x7f,
|
||||
0x00 /* null-terminate */
|
||||
0x7f, 0x00 /* null-terminate */
|
||||
};
|
||||
size_t n = strlen(part);
|
||||
size_t nfine = strcspn(part, badbytes);
|
||||
if(nfine != n)
|
||||
/* since we don't know which part is scanned, return a generic error
|
||||
code */
|
||||
return CURLUE_MALFORMED_INPUT;
|
||||
return TRUE;
|
||||
if(!(flags & CURLU_ALLOW_SPACE) && strchr(part, ' '))
|
||||
return TRUE;
|
||||
}
|
||||
return CURLUE_OK;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static CURLUcode hostname_check(struct Curl_URL *u, char *hostname)
|
||||
|
|
@ -884,9 +885,8 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
|
|||
!(flags & CURLU_NON_SUPPORT_SCHEME))
|
||||
return CURLUE_UNSUPPORTED_SCHEME;
|
||||
|
||||
if(junkscan(schemep))
|
||||
if(junkscan(schemep, flags))
|
||||
return CURLUE_MALFORMED_INPUT;
|
||||
|
||||
}
|
||||
else {
|
||||
/* no scheme! */
|
||||
|
|
@ -927,7 +927,7 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
|
|||
}
|
||||
}
|
||||
|
||||
if(junkscan(path))
|
||||
if(junkscan(path, flags))
|
||||
return CURLUE_MALFORMED_INPUT;
|
||||
|
||||
if((flags & CURLU_URLENCODE) && path[0]) {
|
||||
|
|
@ -991,7 +991,7 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
|
|||
/*
|
||||
* Parse the login details and strip them out of the host name.
|
||||
*/
|
||||
if(junkscan(hostname))
|
||||
if(junkscan(hostname, flags))
|
||||
return CURLUE_MALFORMED_INPUT;
|
||||
|
||||
result = parse_hostname_login(u, &hostname, flags);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue