summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-05-20 10:51:53 +0200
committerDaniel Stenberg <daniel@haxx.se>2019-05-20 10:51:53 +0200
commitb2c5ea9a9e2148c1e6dad8961d2733951e1e9a60 (patch)
treed83c6b8d1e79253b1b9ea63f7f3aa5389bf27b37
parent10db3ef21eef1c7a1727579952a81ced2f4afc8b (diff)
downloadcurl-bagder/curl-no-is-for-boolean.tar.gz
curl: report error for "--no-" on non-boolean optionsbagder/curl-no-is-for-boolean
Reported-by: Olen Andoni Fixes #3906
-rw-r--r--src/tool_getparam.c5
-rw-r--r--src/tool_getparam.h3
-rw-r--r--src/tool_helpers.c4
-rw-r--r--tests/data/Makefile.inc2
-rw-r--r--tests/data/test33335
5 files changed, 46 insertions, 3 deletions
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index b133cb87e..b347121f8 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -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 */
diff --git a/src/tool_getparam.h b/src/tool_getparam.h
index daf83b884..f6fcd5a35 100644
--- a/src/tool_getparam.h
+++ b/src/tool_getparam.h
@@ -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;
diff --git a/src/tool_helpers.c b/src/tool_helpers.c
index b3a9516a8..61788b7f8 100644
--- a/src/tool_helpers.c
+++ b/src/tool_helpers.c
@@ -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";
}
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index 9b26b1e0a..afea1fb83 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -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
index 000000000..198af9c86
--- /dev/null
+++ b/tests/data/test333
@@ -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>