From 4bc8ef42d4f294bf6fec6d728ef27abbb638b98d Mon Sep 17 00:00:00 2001 From: Harley Laue Date: Thu, 2 May 2013 14:44:41 -0500 Subject: [PATCH 1/2] strings.Split may return an empty string on no match * This fixes an index out of range crash if cgroup memory is not enabled. --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 297b798af8..feee84077c 100644 --- a/utils.go +++ b/utils.go @@ -445,7 +445,7 @@ func FindCgroupMountpoint(cgroupType string) (string, error) { // cgroup /sys/fs/cgroup/devices cgroup rw,relatime,devices 0 0 for _, line := range strings.Split(string(output), "\n") { parts := strings.Split(line, " ") - if parts[2] == "cgroup" { + if len(parts) > 1 && parts[2] == "cgroup" { for _, opt := range strings.Split(parts[3], ",") { if opt == cgroupType { return parts[1], nil From 589d7c68dbfe0cf4a84b96b799871bfbff4a5970 Mon Sep 17 00:00:00 2001 From: Harley Laue Date: Fri, 3 May 2013 13:49:10 -0500 Subject: [PATCH 2/2] Check that the line is valid with 6 parts after split --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index feee84077c..4bdbd1253b 100644 --- a/utils.go +++ b/utils.go @@ -445,7 +445,7 @@ func FindCgroupMountpoint(cgroupType string) (string, error) { // cgroup /sys/fs/cgroup/devices cgroup rw,relatime,devices 0 0 for _, line := range strings.Split(string(output), "\n") { parts := strings.Split(line, " ") - if len(parts) > 1 && parts[2] == "cgroup" { + if len(parts) == 6 && parts[2] == "cgroup" { for _, opt := range strings.Split(parts[3], ",") { if opt == cgroupType { return parts[1], nil