]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: move pointer dereference after check
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Mar 2020 10:05:11 +0000 (11:05 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Mar 2020 10:47:49 +0000 (11:47 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index ad37291e97892d03f2ade0a7b756e0788d634d8b..387350b4363fc54ea1748e1a6a82dee2ef148c0f 100644 (file)
@@ -2124,8 +2124,8 @@ struct userns_exec_unified_attach_data {
 static int cgroup_unified_attach_wrapper(void *data)
 {
        struct userns_exec_unified_attach_data *args = data;
-       uid_t nsuid = (args->conf->root_nsuid_map != NULL) ? 0 : args->conf->init_uid;
-       gid_t nsgid = (args->conf->root_nsgid_map != NULL) ? 0 : args->conf->init_gid;
+       uid_t nsuid;
+       gid_t nsgid;
        int ret;
 
        if (!args->conf || args->unified_fd < 0 || args->pid <= 0)
@@ -2134,6 +2134,9 @@ static int cgroup_unified_attach_wrapper(void *data)
        if (!lxc_setgroups(0, NULL) && errno != EPERM)
                return log_error_errno(-1, errno, "Failed to setgroups(0, NULL)");
 
+       nsuid = (args->conf->root_nsuid_map != NULL) ? 0 : args->conf->init_uid;
+       nsgid = (args->conf->root_nsgid_map != NULL) ? 0 : args->conf->init_gid;
+
        ret = setresgid(nsgid, nsgid, nsgid);
        if (ret < 0)
                return log_error_errno(-1, errno, "Failed to setresgid(%d, %d, %d)",