]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: don't double free in get_minimal_idmap()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 15 Apr 2020 11:51:51 +0000 (13:51 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 15 Apr 2020 12:10:30 +0000 (14:10 +0200)
Fixes: Coverity 1461725.
Fixes: Coverity 1461727.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 5bbc1a1d71af909328bb80ad10d279f8ae3c9219..474b01f92eeb3527348525b5cf4eb4164edbeacd 100644 (file)
@@ -3954,7 +3954,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
        euid = geteuid();
        if (euid >= container_root_uid->hostid &&
            euid < (container_root_uid->hostid + container_root_uid->range))
-               host_uid_map = container_root_uid;
+               host_uid_map = move_ptr(container_root_uid);
 
        container_root_gid = mapped_nsid_add(conf, nsgid, ID_TYPE_GID);
        if (!container_root_gid)
@@ -3962,7 +3962,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
        egid = getegid();
        if (egid >= container_root_gid->hostid &&
            egid < (container_root_gid->hostid + container_root_gid->range))
-               host_gid_map = container_root_gid;
+               host_gid_map = move_ptr(container_root_gid);
 
        /* Check whether the {g,u}id of the user has a mapping. */
        if (!host_uid_map)
@@ -3988,7 +3988,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
        lxc_list_add_elem(tmplist, container_root_uid);
        lxc_list_add_tail(idmap, tmplist);
 
-       if (host_uid_map != container_root_uid) {
+       if (container_root_uid) {
                /* idmap will now keep track of that memory. */
                move_ptr(container_root_uid);
 
@@ -4010,7 +4010,7 @@ static struct lxc_list *get_minimal_idmap(const struct lxc_conf *conf,
        lxc_list_add_elem(tmplist, container_root_gid);
        lxc_list_add_tail(idmap, tmplist);
 
-       if (host_gid_map != container_root_gid) {
+       if (container_root_gid) {
                /* idmap will now keep track of that memory. */
                move_ptr(container_root_gid);