]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: prevent NULL pointer deref 3679/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 17 Feb 2021 13:36:10 +0000 (14:36 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 17 Feb 2021 13:42:55 +0000 (14:42 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index 8400011d1af98dd47e2b2c3b797aefa051f520e2..287d17453a66509b1d8a8daba1a5db25f39f69cf 100644 (file)
@@ -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