diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index 162195d8e..5713460e4 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -758,7 +758,7 @@ func initSystemdProps(spec *specs.Spec) ([]systemdDbus.Property, error) { return nil, fmt.Errorf("annotation %s=%s value parse error: %w", k, v, err) } // Check for Sec suffix. - if trimName := strings.TrimSuffix(name, "Sec"); len(trimName) < len(name) { + if trimName, ok := strings.CutSuffix(name, "Sec"); ok && len(trimName) > 0 { // Check for a lowercase ascii a-z just before Sec. if ch := trimName[len(trimName)-1]; ch >= 'a' && ch <= 'z' { // Convert from Sec to USec. diff --git a/libcontainer/specconv/spec_linux_test.go b/libcontainer/specconv/spec_linux_test.go index e514b4f31..d415911fc 100644 --- a/libcontainer/specconv/spec_linux_test.go +++ b/libcontainer/specconv/spec_linux_test.go @@ -749,6 +749,11 @@ func TestInitSystemdProps(t *testing.T) { in: inT{"org.systemd.property.FOOSec", "123"}, exp: expT{false, "FOOSec", 123}, }, + { + desc: "convert USec to Sec (short name)", + in: inT{"org.systemd.property.Sec", "123"}, + exp: expT{false, "Sec", 123}, + }, { desc: "CollectMode", in: inT{"org.systemd.property.CollectMode", "'inactive-or-failed'"},