]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_paramhlp: refuse --proto remove all protocols
authorDaniel Stenberg <daniel@haxx.se>
Thu, 6 Nov 2025 22:14:04 +0000 (23:14 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 6 Nov 2025 22:42:47 +0000 (23:42 +0100)
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 #19388

src/tool_paramhlp.c
tests/data/test1474

index 9f54704ea2ed25b82aceb42f7bc2cadbaacdd395..008f0fc388c12a507e8db83285928fa45c66ffbd 100644 (file)
@@ -397,7 +397,7 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str)
   const char **protoset;
   struct dynbuf obuf;
   size_t proto;
-  CURLcode result;
+  CURLcode result = CURLE_OK;
 
   curlx_dyn_init(&obuf, MAX_PROTOSTRING);
 
@@ -496,15 +496,19 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str)
   qsort((char *) protoset, protoset_index(protoset, NULL), sizeof(*protoset),
         struplocompare4sort);
 
-  result = curlx_dyn_addn(&obuf, "", 0);
   for(proto = 0; protoset[proto] && !result; proto++)
-    result = curlx_dyn_addf(&obuf, "%s,", protoset[proto]);
+    result = curlx_dyn_addf(&obuf, "%s%s", curlx_dyn_len(&obuf) ? "," : "",
+                            protoset[proto]);
   free((char *) protoset);
-  curlx_dyn_setlen(&obuf, curlx_dyn_len(&obuf) - 1);
+  if(result)
+    return PARAM_NO_MEM;
+  if(!curlx_dyn_len(&obuf)) {
+    curlx_dyn_free(&obuf);
+    return PARAM_BAD_USE;
+  }
   free(*ostr);
   *ostr = curlx_dyn_ptr(&obuf);
-
-  return *ostr ? PARAM_OK : PARAM_NO_MEM;
+  return PARAM_OK;
 }
 
 /**
index 8ccecf18775bdaa91c56b7645e3adfc90b5a6a50..9ca209cf269480e1d6188e6168de86f57bcb65a2 100644 (file)
@@ -29,9 +29,9 @@ http
 #
 # Verify data after the test has been "shot"
 <verify>
-# 1 - Protocol "http" disabled
+# 2 failed init, the --proto argument is not accepted
 <errorcode>
-1
+2
 </errorcode>
 </verify>
 </testcase>