Skip to content

Commit

Permalink
tool_getparam: handle non-existing (out of range) short-options
Browse files Browse the repository at this point in the history
... correctly, even when they follow an existing one without a space in
between.

Verify with test 467

Follow-up to 07dd60c
Reported-by: Geeknik Labs
Fixes #13101
Closes #131..
  • Loading branch information
bagder committed Mar 11, 2024
1 parent 6aeb729 commit 4adc6e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/tool_getparam.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Makefile.inc
Expand Up @@ -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 \
Expand Down
31 changes: 31 additions & 0 deletions tests/data/test467
@@ -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 http://example.com
</command>
</client>

#
# Verify errorcode
<verify>
<errorcode>
2
</errorcode>
</verify>
</testcase>

0 comments on commit 4adc6e0

Please sign in to comment.