mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53: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>
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)
|
return nil, fmt.Errorf("annotation %s=%s value parse error: %w", k, v, err)
|
||||||
}
|
}
|
||||||
// Check for Sec suffix.
|
// 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.
|
// Check for a lowercase ascii a-z just before Sec.
|
||||||
if ch := trimName[len(trimName)-1]; ch >= 'a' && ch <= 'z' {
|
if ch := trimName[len(trimName)-1]; ch >= 'a' && ch <= 'z' {
|
||||||
// Convert from Sec to USec.
|
// Convert from Sec to USec.
|
||||||
|
|||||||
@@ -750,6 +750,11 @@ func TestInitSystemdProps(t *testing.T) {
|
|||||||
in: inT{"org.systemd.property.FOOSec", "123"},
|
in: inT{"org.systemd.property.FOOSec", "123"},
|
||||||
exp: expT{false, "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",
|
desc: "CollectMode",
|
||||||
in: inT{"org.systemd.property.CollectMode", "'inactive-or-failed'"},
|
in: inT{"org.systemd.property.CollectMode", "'inactive-or-failed'"},
|
||||||
|
|||||||
Reference in New Issue
Block a user