[lxc-devel] [PATCH] prune_init_cgroup: don't dereference NULL

Serge Hallyn serge.hallyn at ubuntu.com
Sat Dec 5 00:26:37 UTC 2015


This is to avoid:

https://errors.ubuntu.com/problem/d640a68bf7343705899d7ca8c6bc070d477cd845

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/cgroup.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
index b1c764f..9894fb7 100644
--- a/src/lxc/cgroup.c
+++ b/src/lxc/cgroup.c
@@ -198,7 +198,14 @@ cgroup_driver_t cgroup_driver(void)
 #define INIT_SCOPE "/init.scope"
 void prune_init_scope(char *cg)
 {
-	char *point = cg + strlen(cg) - strlen(INIT_SCOPE);
+	char *point;
+
+	if (!cg) {
+		WARN("prune_init_scope called with NULL")
+		return;
+	}
+
+	point = cg + strlen(cg) - strlen(INIT_SCOPE);
 	if (point < cg)
 		return;
 	if (strcmp(point, INIT_SCOPE) == 0) {
-- 
2.5.0



More information about the lxc-devel mailing list