diff --git a/cgroup.go b/cgroup.go index 6e4cc84..de06a05 100644 --- a/cgroup.go +++ b/cgroup.go @@ -128,9 +128,9 @@ func currentProcCgroup(fs afero.Fs) (string, error) { entries := strings.Split(strings.TrimSpace(string(data)), "\n") for _, entry := range entries { - parts := strings.Split(strings.TrimSpace(entry), ":") + parts := strings.SplitN(strings.TrimSpace(entry), ":", 3) if len(parts) != 3 { - return "", xerrors.Errorf("parse entry %v: %w", procSelfCgroup, err) + return "", xerrors.Errorf("parse entry %v: expected at least 3 colon-separated fields in %q", procSelfCgroup, entry) } if parts[0] == "0" { diff --git a/cgroup_internal_test.go b/cgroup_internal_test.go index ff3c0fd..8214c3d 100644 --- a/cgroup_internal_test.go +++ b/cgroup_internal_test.go @@ -54,6 +54,22 @@ func TestCurrentProcCgroup(t *testing.T) { 1:net_cls:/`, expectPath: "/init.slice", }, + { + name: "ExtraColonsInPath", + procFile: `0::/system.slice/kubepods-burstable.slice:cri-containerd:d24f9cc`, + expectPath: "/system.slice/kubepods-burstable.slice:cri-containerd:d24f9cc", + }, + { + name: "ExtraColonsInPathWithMixedHierarchy", + procFile: `1:net_cls:/init.slice +0::/system.slice/kubepods.slice:cri-containerd:abc123`, + expectPath: "/system.slice/kubepods.slice:cri-containerd:abc123", + }, + { + name: "MalformedEntryTooFewFields", + procFile: `0`, + expectError: "parse entry", + }, { name: "MissingHierarchy0", procFile: `1:net_cls:/`,