setopt: Fix disabling all protocols

When disabling all protocols without enabling any, the resulting
set of allowed protocols remained the default set.  Clearing the
allowed set before inspecting the passed value from --proto make
the set empty even in the errorpath of no protocols enabled.

Co-authored-by: Dan Fandrich <dan@telarity.com>
Reported-by: Dan Fandrich <dan@telarity.com>
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
Closes: #13004
This commit is contained in:
Daniel Gustafsson 2024-02-27 15:43:56 +01:00
parent f0eacd9447
commit 17d302e562
3 changed files with 51 additions and 9 deletions

View file

@ -155,6 +155,12 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
static CURLcode protocol2num(const char *str, curl_prot_t *val)
{
/*
* We are asked to cherry-pick protocols, so play it safe and disallow all
* protocols to start with, and re-add the wanted ones back in.
*/
*val = 0;
if(!str)
return CURLE_BAD_FUNCTION_ARGUMENT;
@ -163,8 +169,6 @@ static CURLcode protocol2num(const char *str, curl_prot_t *val)
return CURLE_OK;
}
*val = 0;
do {
const char *token = str;
size_t tlen;
@ -2654,22 +2658,18 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
break;
case CURLOPT_PROTOCOLS_STR: {
curl_prot_t prot;
argptr = va_arg(param, char *);
result = protocol2num(argptr, &prot);
result = protocol2num(argptr, &data->set.allowed_protocols);
if(result)
return result;
data->set.allowed_protocols = prot;
break;
}
case CURLOPT_REDIR_PROTOCOLS_STR: {
curl_prot_t prot;
argptr = va_arg(param, char *);
result = protocol2num(argptr, &prot);
result = protocol2num(argptr, &data->set.redir_protocols);
if(result)
return result;
data->set.redir_protocols = prot;
break;
}