Skip to content

Commit 8e93a74

Browse files
committed
tool_paramhlp: refuse --proto remove all protocols
curl is for transfers so disabling all protocols has to be a mistake. Previously it would allow this to get set (even if curl_easy_setopt() returns an error for it) and then let libcurl return error instead. Updated 1474 accordingly. Closes curl#19388
1 parent e108778 commit 8e93a74

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/tool_paramhlp.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str)
397397
const char **protoset;
398398
struct dynbuf obuf;
399399
size_t proto;
400-
CURLcode result;
400+
CURLcode result = CURLE_OK;
401401

402402
curlx_dyn_init(&obuf, MAX_PROTOSTRING);
403403

@@ -496,15 +496,19 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str)
496496
qsort((char *) protoset, protoset_index(protoset, NULL), sizeof(*protoset),
497497
struplocompare4sort);
498498

499-
result = curlx_dyn_addn(&obuf, "", 0);
500499
for(proto = 0; protoset[proto] && !result; proto++)
501-
result = curlx_dyn_addf(&obuf, "%s,", protoset[proto]);
500+
result = curlx_dyn_addf(&obuf, "%s%s", curlx_dyn_len(&obuf) ? "," : "",
501+
protoset[proto]);
502502
free((char *) protoset);
503-
curlx_dyn_setlen(&obuf, curlx_dyn_len(&obuf) - 1);
503+
if(result)
504+
return PARAM_NO_MEM;
505+
if(!curlx_dyn_len(&obuf)) {
506+
curlx_dyn_free(&obuf);
507+
return PARAM_BAD_USE;
508+
}
504509
free(*ostr);
505510
*ostr = curlx_dyn_ptr(&obuf);
506-
507-
return *ostr ? PARAM_OK : PARAM_NO_MEM;
511+
return PARAM_OK;
508512
}
509513

510514
/**

tests/data/test1474

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ http
2929
#
3030
# Verify data after the test has been "shot"
3131
<verify>
32-
# 1 - Protocol "http" disabled
32+
# 2 failed init, the --proto argument is not accepted
3333
<errorcode>
34-
1
34+
2
3535
</errorcode>
3636
</verify>
3737
</testcase>

0 commit comments

Comments
 (0)