2e7c137
From c8dac4ba172c145dbdf924a5e309fe7539b3610e Mon Sep 17 00:00:00 2001
2e7c137
From: Daniel Gustafsson <daniel@yesql.se>
2e7c137
Date: Tue, 27 Feb 2024 15:43:56 +0100
2e7c137
Subject: [PATCH 1/2] setopt: Fix disabling all protocols
2e7c137
2e7c137
When disabling all protocols without enabling any, the resulting
2e7c137
set of allowed protocols remained the default set.  Clearing the
2e7c137
allowed set before inspecting the passed value from --proto make
2e7c137
the set empty even in the errorpath of no protocols enabled.
2e7c137
2e7c137
Co-authored-by: Dan Fandrich <dan@telarity.com>
2e7c137
Reported-by: Dan Fandrich <dan@telarity.com>
2e7c137
Reviewed-by: Daniel Stenberg <daniel@haxx.se>
2e7c137
Closes: #13004
2e7c137
(cherry picked from commit 17d302e56221f5040092db77d4f85086e8a20e0e)
2e7c137
Signed-off-by: Jan Macku <jamacku@redhat.com>
2e7c137
---
2e7c137
 lib/setopt.c            | 16 ++++++++--------
2e7c137
 tests/data/Makefile.inc |  2 +-
2e7c137
 tests/data/test1474     | 42 +++++++++++++++++++++++++++++++++++++++++
2e7c137
 3 files changed, 51 insertions(+), 9 deletions(-)
2e7c137
 create mode 100644 tests/data/test1474
2e7c137
2e7c137
diff --git a/lib/setopt.c b/lib/setopt.c
2e7c137
index a5270773f..3891eb679 100644
2e7c137
--- a/lib/setopt.c
2e7c137
+++ b/lib/setopt.c
2e7c137
@@ -155,6 +155,12 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
2e7c137
 
2e7c137
 static CURLcode protocol2num(const char *str, curl_prot_t *val)
2e7c137
 {
2e7c137
+  /*
2e7c137
+   * We are asked to cherry-pick protocols, so play it safe and disallow all
2e7c137
+   * protocols to start with, and re-add the wanted ones back in.
2e7c137
+   */
2e7c137
+  *val = 0;
2e7c137
+
2e7c137
   if(!str)
2e7c137
     return CURLE_BAD_FUNCTION_ARGUMENT;
2e7c137
 
2e7c137
@@ -163,8 +169,6 @@ static CURLcode protocol2num(const char *str, curl_prot_t *val)
2e7c137
     return CURLE_OK;
2e7c137
   }
2e7c137
 
2e7c137
-  *val = 0;
2e7c137
-
2e7c137
   do {
2e7c137
     const char *token = str;
2e7c137
     size_t tlen;
2e7c137
@@ -2657,22 +2661,18 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
2e7c137
     break;
2e7c137
 
2e7c137
   case CURLOPT_PROTOCOLS_STR: {
2e7c137
-    curl_prot_t prot;
2e7c137
     argptr = va_arg(param, char *);
2e7c137
-    result = protocol2num(argptr, &prot;;
2e7c137
+    result = protocol2num(argptr, &data->set.allowed_protocols);
2e7c137
     if(result)
2e7c137
       return result;
2e7c137
-    data->set.allowed_protocols = prot;
2e7c137
     break;
2e7c137
   }
2e7c137
 
2e7c137
   case CURLOPT_REDIR_PROTOCOLS_STR: {
2e7c137
-    curl_prot_t prot;
2e7c137
     argptr = va_arg(param, char *);
2e7c137
-    result = protocol2num(argptr, &prot;;
2e7c137
+    result = protocol2num(argptr, &data->set.redir_protocols);
2e7c137
     if(result)
2e7c137
       return result;
2e7c137
-    data->set.redir_protocols = prot;
2e7c137
     break;
2e7c137
   }
2e7c137
 
2e7c137
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
2e7c137
index cd393da75..011aa4607 100644
2e7c137
--- a/tests/data/Makefile.inc
2e7c137
+++ b/tests/data/Makefile.inc
2e7c137
@@ -186,7 +186,7 @@ test1439 test1440 test1441 test1442 test1443 test1444 test1445 test1446 \
2e7c137
 test1447 test1448 test1449 test1450 test1451 test1452 test1453 test1454 \
2e7c137
 test1455 test1456 test1457 test1458 test1459 test1460 test1461 test1462 \
2e7c137
 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test1470 \
2e7c137
-test1471 test1472 test1473          test1475 test1476 test1477 test1478 \
2e7c137
+test1471 test1472 test1473 test1474 test1475 test1476 test1477 test1478 \
2e7c137
 \
2e7c137
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
2e7c137
 test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
2e7c137
diff --git a/tests/data/test1474 b/tests/data/test1474
2e7c137
new file mode 100644
2e7c137
index 000000000..c66fa2810
2e7c137
--- /dev/null
2e7c137
+++ b/tests/data/test1474
2e7c137
@@ -0,0 +1,42 @@
2e7c137
+<testcase>
2e7c137
+<info>
2e7c137
+<keywords>
2e7c137
+HTTP
2e7c137
+HTTP GET
2e7c137
+--proto
2e7c137
+</keywords>
2e7c137
+</info>
2e7c137
+
2e7c137
+#
2e7c137
+# Server-side
2e7c137
+<reply>
2e7c137
+<data>
2e7c137
+</data>
2e7c137
+</reply>
2e7c137
+
2e7c137
+#
2e7c137
+# Client-side
2e7c137
+<client>
2e7c137
+<server>
2e7c137
+none
2e7c137
+</server>
2e7c137
+<features>
2e7c137
+http
2e7c137
+</features>
2e7c137
+<name>
2e7c137
+--proto -all disables all protocols
2e7c137
+</name>
2e7c137
+<command>
2e7c137
+--proto -all http://%HOSTIP:%NOLISTENPORT/%TESTNUMBER
2e7c137
+</command>
2e7c137
+</client>
2e7c137
+
2e7c137
+#
2e7c137
+# Verify data after the test has been "shot"
2e7c137
+<verify>
2e7c137
+# 1 - Protocol "http" disabled
2e7c137
+<errorcode>
2e7c137
+1
2e7c137
+</errorcode>
2e7c137
+</verify>
2e7c137
+</testcase>
2e7c137
-- 
2e7c137
2.44.0
2e7c137