]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_getparam: handle non-existing (out of range) short-options
authorDaniel Stenberg <daniel@haxx.se>
Mon, 11 Mar 2024 21:39:22 +0000 (22:39 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 12 Mar 2024 06:58:42 +0000 (07:58 +0100)
... correctly, even when they follow an existing one without a space in
between.

Verify with test 467

Follow-up to 07dd60c05b
Reported-by: Geeknik Labs
Fixes #13101
Closes #13102

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

index 23fe3106e6d4129064cfce92ab136c07b8d6d511..52bb24959ddd71db0abb6d7210899c1e5c35a104 100644 (file)
@@ -1009,7 +1009,8 @@ static const struct LongShort *single(char letter)
 {
   static const struct LongShort *singles[128 - ' ']; /* ASCII => pointer */
   static bool singles_done = FALSE;
-  DEBUGASSERT((letter < 127) && (letter > ' '));
+  if((letter >= 127) || (letter <= ' '))
+    return NULL;
 
   if(!singles_done) {
     unsigned int j;
index 1a06adf37b97b41833e2bdaa93ce5bb72a5805a5..06bc5c54f9647553ed9353f329d350baec540492 100644 (file)
@@ -73,7 +73,7 @@ test426 test427 test428 test429 test430 test431 test432 test433 test434 \
 test435 test436 test437 test438 test439 test440 test441 test442 test443 \
 test444 test445 test446 test447 test448 test449 test450 test451 test452 \
 test453 test454 test455 test456 test457 test458 test459 test460 test461 \
-test462 test463 \
+test462 test463 test467 \
 \
 test490 test491 test492 test493 test494 test495 test496 test497 test498 \
 test499 test500 test501 test502 test503 test504 test505 test506 test507 \
diff --git a/tests/data/test467 b/tests/data/test467
new file mode 100644 (file)
index 0000000..4184ac0
--- /dev/null
@@ -0,0 +1,31 @@
+<testcase>
+<info>
+<keywords>
+cmdline
+</keywords>
+</info>
+
+#
+# Client-side
+<client>
+<server>
+none
+</server>
+<name>
+use a bad short option letter that does not exist (after one does exist)
+</name>
+
+# the second option is outside the normal accepted range
+<command>
+curl -v\b http://example.com
+</command>
+</client>
+
+#
+# Verify errorcode
+<verify>
+<errorcode>
+2
+</errorcode>
+</verify>
+</testcase>