Skip to content

Commit

Permalink
conf: don't double free in get_minimal_idmap()
Browse files Browse the repository at this point in the history
Fixes: Coverity 1461725.
Fixes: Coverity 1461727.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Apr 15, 2020
1 parent 7484656 commit 2c99621
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lxc/conf.c
Expand Up @@ -3954,15 +3954,15 @@ 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)
return log_debug(NULL, "Failed to find mapping for namespace gid %d", 0);
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)
Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 2c99621

Please sign in to comment.