urlapi: detect scheme better when not guessing

When the parser is not allowed to guess scheme, it should consider the
word ending at the first colon to be the scheme, independently of number
of slashes.

The parser now checks that the scheme is known before it counts slashes,
to improve the error messge for URLs with unknown schemes and maybe no
slashes.

When following redirects, no scheme guessing is allowed and therefore
this change effectively prevents redirects to unknown schemes such as
"data".

Fixes #9503
This commit is contained in:
Daniel Stenberg 2022-09-14 09:18:30 +02:00
parent 7f5fe74323
commit 846678541b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 30 additions and 14 deletions

View file

@ -25,7 +25,8 @@
***************************************************************************/
#include "curl_setup.h"
size_t Curl_is_absolute_url(const char *url, char *buf, size_t buflen);
size_t Curl_is_absolute_url(const char *url, char *buf, size_t buflen,
bool guess_scheme);
#ifdef DEBUGBUILD
CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host,