From cd704e80ee74b027660c43d72770633bebd85ad2 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Tue, 15 Jul 2014 17:04:11 +0400 Subject: [PATCH] cgroups: Make sure the cgroup formatted correctly In case if something is broken in the kernel and we get a format corrupted -- simply exit out with error instead of strlen'ing nil string. Also while at it -- add a comment about format. Signed-off-by: Cyrill Gorcunov Acked-by: Tycho Andersen Signed-off-by: Pavel Emelyanov --- proc_parse.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/proc_parse.c b/proc_parse.c index 88f3c0a9c..1c6678258 100644 --- a/proc_parse.c +++ b/proc_parse.c @@ -1530,8 +1530,20 @@ int parse_task_cgroup(int pid, struct list_head *retl, unsigned int *n) if (!ncc) goto err; + /* + * Typical output (':' is a separator here) + * + * 4:cpu,cpuacct:/ + * 3:cpuset:/ + * 2:name=systemd:/user.slice/user-1000.slice/session-1.scope + */ name = strchr(buf, ':') + 1; path = strchr(name, ':'); + if (!name || !path) { + pr_err("Failed parsing cgroup %s\n", buf); + xfree(ncc); + goto err; + } e = strchr(name, '\n'); *path++ = '\0'; if (e)