kotlinx-cli icon indicating copy to clipboard operation
kotlinx-cli copied to clipboard

Incorrect handling of "--" in GNU mode

Open FerrumBrain opened this issue 11 months ago • 0 comments

Next entries are considered options when -- is encountered in GNU mode. However, there is no check to ensure that they exist. In the following test case:

val parser = ArgParser("").apply {
    argument(ArgType.String, fullName = "")
    prefixStyle = ArgParser.OptionPrefixStyle.GNU
}    

val args = arrayOf("--")
parser.parse(args)

Many results can be considered correct:

  • String "--" is interpreted as a delimiter between options and arguments, parsing is successful with no options and no arguments
  • String "--" is interpreted as an argument and parsing is successful
  • String "--" is interpreted as a start of the option and the parser fails with a descriptive error because no options are registered

In practice though, it throws an ArrayOutOfBoundsException. Bug is found by fuzzing team @ PLAN Lab.

FerrumBrain avatar Dec 16 '24 16:12 FerrumBrain