bugfix: do not try to parse empty ranges

An empty range caused a panic as parseOptionIDs tried to check further
down for an @ at index 0 without taking into account that the splitted
out string could be empty.

Signed-off-by: Simon Brakhane <simon@brakhane.net>
This commit is contained in:
Simon Brakhane
2023-07-06 11:06:34 +02:00
parent f1775a34ab
commit dee94ea699
2 changed files with 7 additions and 0 deletions

View File

@ -65,6 +65,10 @@ func parseOptionIDs(ctrMappings []idtools.IDMap, option string) ([]idtools.IDMap
for i, m := range ranges {
var v idtools.IDMap
if m == "" {
return nil, fmt.Errorf("invalid empty range for %q", option)
}
relative := false
if m[0] == '@' {
relative = true

View File

@ -70,6 +70,9 @@ func TestParseOptionIDs(t *testing.T) {
_, err = parseOptionIDs(idMap, "@10000-20000-2")
assert.NotNil(t, err)
_, err = parseOptionIDs(idMap, "100-200-3###400-500-6")
assert.NotNil(t, err)
}
func TestParseIDMapMountOption(t *testing.T) {