]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: report error for "--no-" on non-boolean options
authorDaniel Stenberg <daniel@haxx.se>
Mon, 20 May 2019 08:51:53 +0000 (10:51 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 20 May 2019 17:04:54 +0000 (19:04 +0200)
Reported-by: Olen Andoni
Fixes #3906
Closes #3907

src/tool_getparam.c
src/tool_getparam.h
src/tool_helpers.c
tests/data/Makefile.inc
tests/data/test333 [new file with mode: 0644]

index b133cb87edb115ffd089592188669eb94d615ff7..b347121f88141b4cc00a8d2e23eb5fd2c20453b5 100644 (file)
@@ -515,11 +515,13 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
     const char *word = ('-' == flag[0]) ? flag + 2 : flag;
     size_t fnam = strlen(word);
     int numhits = 0;
+    bool noflagged = FALSE;
 
     if(!strncmp(word, "no-", 3)) {
       /* disable this option but ignore the "no-" part when looking for it */
       word += 3;
       toggle = FALSE;
+      noflagged = TRUE;
     }
 
     for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
@@ -543,6 +545,9 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
     if(hit < 0) {
       return PARAM_OPTION_UNKNOWN;
     }
+    if(noflagged && (aliases[hit].desc != ARG_BOOL))
+      /* --no- prefixed an option that isn't boolean! */
+      return PARAM_NO_NOT_BOOLEAN;
   }
   else {
     flag++; /* prefixed with one dash, pass it */
index daf83b884312d02a7c4b40b5ffb5fdee73f2154e..f6fcd5a3584eca1a967abcaa8cf207114facb70b 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -42,6 +42,7 @@ typedef enum {
   PARAM_NEXT_OPERATION,
   PARAM_NO_PREFIX,
   PARAM_NUMBER_TOO_LARGE,
+  PARAM_NO_NOT_BOOLEAN,
   PARAM_LAST
 } ParameterError;
 
index b3a9516a8014ae8f681fb48c8e4aa9529bc006f3..61788b7f8f46783c3a3a1e2107ad6d357a37f30a 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -66,6 +66,8 @@ const char *param2text(int res)
     return "the given option can't be reversed with a --no- prefix";
   case PARAM_NUMBER_TOO_LARGE:
     return "too large number";
+  case PARAM_NO_NOT_BOOLEAN:
+    return "used '--no-' for option that isn't a boolean";
   default:
     return "unknown error";
   }
index 9b26b1e0a6b8c6cb236d1db5b58ab08249ef410f..afea1fb838dd99b8eb85ec1c090aa73b212b370d 100644 (file)
@@ -56,7 +56,7 @@ test289 test290 test291 test292 test293 test294 test295 test296 test297 \
 test298 test299 test300 test301 test302 test303 test304 test305 test306 \
 test307 test308 test309 test310 test311 test312 test313 test314 test315 \
 test316 test317 test318 test319 test320 test321 test322 test323 test324 \
-test325 test326 test327 test328 test329 test330 test331 test332 \
+test325 test326 test327 test328 test329 test330 test331 test332 test333 \
 \
 test340 \
 \
diff --git a/tests/data/test333 b/tests/data/test333
new file mode 100644 (file)
index 0000000..198af9c
--- /dev/null
@@ -0,0 +1,35 @@
+<testcase>
+<info>
+<keywords>
+command-line
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+none
+</server>
+ <name>
+Try a non-boolean command line option with --no-
+ </name>
+ <command>
+--no-proxy "hey" http://%HOSTIP:%HTTPPORT/333
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+# detected the bad --no- prefix
+<errorcode>
+2
+</errorcode>
+</verify>
+</testcase>