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 committed 2023-07-06 11:16:34 +02:00
1 parent f1775a34ab
commit dee94ea699
2 files changed
+7

No files matched your search

+4
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
+3
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) {