Skip to content

Fix panic on empty-string value for list options - #11347

Open
nikolauspschuetz wants to merge 1 commit into
dolthub:mainfrom
nikolauspschuetz:fix-argparser-empty-list-value-panic
Open

Fix panic on empty-string value for list options#11347
nikolauspschuetz wants to merge 1 commit into
dolthub:mainfrom
nikolauspschuetz:fix-argparser-empty-list-value-panic

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

What

getListValues (go/libraries/utils/argparser/parser.go) checked arg[0] == '-' without a length guard, so an empty-string value for any list-valued option panicked:

panic: runtime error: index out of range [0] with length 0
    .../argparser/parser.go:499

This is reachable from the CLI for any option built with SupportsStringList (i.e. AllowMultipleOptions), e.g.:

dolt log --not ""
dolt log -t ""
dolt diff --include-cols ""

Each aborts with a runtime panic instead of accepting the empty value.

Fix

Test for the empty string before indexing arg[0]:

if arg == "--" || (arg != "" && arg[0] == '-') {

An empty value is now collected like any other non-flag argument, and a following option (-l "" -f) still terminates the list.

Testing

Added TestArgParserListEmptyValue, which panics before this change and passes after. The full argparser package tests, go vet, and gofmt are clean.

getListValues checked arg[0] == '-' without a length guard, so an empty
string argument panicked with index out of range. This is reachable from
the CLI for any list-valued option, e.g. dolt log --not "", dolt log
-t "", or dolt diff --include-cols "", which aborted with a runtime
panic instead of accepting the empty value.

Check for the empty string before indexing. Adds a regression test that
panics before this change and passes after.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants