diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index d8a4d026b..fad7b802e 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -538,8 +538,10 @@ func checkPropertyName(s string) error { if len(s) < 3 { return errors.New("too short") } - // Check ASCII characters rather than Unicode runes. - for _, ch := range s { + // Check ASCII characters rather than Unicode runes, + // so we have to use indexes rather than range. + for i := 0; i < len(s); i++ { + ch := s[i] if (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') { continue } diff --git a/libcontainer/specconv/spec_linux_test.go b/libcontainer/specconv/spec_linux_test.go index 1068c55a8..d5a22d890 100644 --- a/libcontainer/specconv/spec_linux_test.go +++ b/libcontainer/specconv/spec_linux_test.go @@ -759,7 +759,7 @@ func TestInitSystemdProps(t *testing.T) { } } -func TestIsValidName(t *testing.T) { +func TestCheckPropertyName(t *testing.T) { testCases := []struct { in string valid bool @@ -784,7 +784,7 @@ func TestIsValidName(t *testing.T) { } } -func BenchmarkIsValidName(b *testing.B) { +func BenchmarkCheckPropertyName(b *testing.B) { for i := 0; i < b.N; i++ { for _, s := range []string{"", "xx", "xxx", "someValidName", "A name", "Кир", "მადლობა", "合い言葉"} { _ = checkPropertyName(s)