From ef983f5180ff5026646c8eae69b67f3f1d8beabc Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 6 Jan 2025 13:37:52 -0800 Subject: [PATCH] libct/cg/fscommon: ParseKeyValue: stricter check It makes sense to report an error if a key or a value is empty, as we don't expect anything like this. Reported-by: Sebastiaan van Stijn Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fscommon/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcontainer/cgroups/fscommon/utils.go b/libcontainer/cgroups/fscommon/utils.go index 76d06e498..9279c064a 100644 --- a/libcontainer/cgroups/fscommon/utils.go +++ b/libcontainer/cgroups/fscommon/utils.go @@ -60,8 +60,8 @@ func ParseUint(s string, base, bitSize int) (uint64, error) { // "io_service_bytes 1234" will be returned as "io_service_bytes", 1234. func ParseKeyValue(t string) (string, uint64, error) { key, val, ok := strings.Cut(t, " ") - if !ok { - return "", 0, fmt.Errorf("line %q is not in key value format", t) + if !ok || key == "" || val == "" { + return "", 0, fmt.Errorf(`line %q is not in "key value" format`, t) } value, err := ParseUint(val, 10, 64)