From bd6403927866738fdc7cdc1c0c18f2e838065637 Mon Sep 17 00:00:00 2001 From: Aditya Rajan Date: Tue, 7 Sep 2021 00:59:18 +0530 Subject: cgroup-info: check if user.slice is valid before accessing value Prevent hitting `panic: runtime error: index out of range [1] with length 1` while performing `podman info` when unexpected values for user.slice is found. [NO TESTS NEEDED] Signed-off-by: Aditya Rajan --- pkg/cgroups/cgroups.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go index 9cb32a364..4bb8de69b 100644 --- a/pkg/cgroups/cgroups.go +++ b/pkg/cgroups/cgroups.go @@ -231,7 +231,10 @@ func getCgroupPathForCurrentProcess() (string, error) { for s.Scan() { text := s.Text() procEntries := strings.SplitN(text, "::", 2) - cgroupPath = procEntries[1] + // set process cgroupPath only if entry is valid + if len(procEntries) > 1 { + cgroupPath = procEntries[1] + } } if err := s.Err(); err != nil { return cgroupPath, err -- cgit v1.2.3-54-g00ecf