mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct/specconv: fix panic in initSystemdProps
There is a chance of panic here -- eliminate it.
Add a test case (which panics before the fix).
Reported-by: Luke Hinds <luke@stacklok.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit a48a7cef96)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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'"},
|
||||
|
||||
Reference in New Issue
Block a user