From: Christian Brauner Date: Wed, 17 Feb 2021 13:36:10 +0000 (+0100) Subject: cgroups: prevent NULL pointer deref X-Git-Tag: lxc-5.0.0~281^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0954f6cec901759673357d1bea48f5cb6dede5b1;p=thirdparty%2Flxc.git cgroups: prevent NULL pointer deref Signed-off-by: Christian Brauner --- diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 8400011d1..287d17453 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -3212,15 +3212,17 @@ static bool __cgfsng_delegate_controllers(struct cgroup_ops *ops, const char *cg { __do_close int dfd_final = -EBADF; __do_free char *add_controllers = NULL, *copy = NULL; - struct hierarchy *unified = ops->unified; - int dfd_cur = unified->dfd_base; - int ret; size_t full_len = 0; + struct hierarchy *unified; + int dfd_cur, ret; char *cur; char **it; - if (!ops->hierarchies || !pure_unified_layout(ops) || - !unified->controllers[0]) + if (!ops->hierarchies || !pure_unified_layout(ops)) + return true; + + unified = ops->unified; + if (!unified->controllers[0]) return true; /* For now we simply enable all controllers that we have detected by @@ -3252,6 +3254,7 @@ static bool __cgfsng_delegate_controllers(struct cgroup_ops *ops, const char *cg * intentional because of the cgroup2 delegation model. It enforces * that leaf cgroups don't have any controllers enabled for delegation. */ + dfd_cur = unified->dfd_base; lxc_iterate_parts(cur, copy, "/") { /* * Even though we vetted the paths when we parsed the config