]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile_utils: cleanup lxc_inherit_namespace()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 9 Dec 2020 09:26:34 +0000 (10:26 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 10 Dec 2020 19:39:53 +0000 (20:39 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile_utils.c
src/lxc/utils.c

index 01ccd0c34196d0ff4407e335fccae3ed1bbce276..5db6febf6bd67add675f71ffea9ad701cb160ac3 100644 (file)
@@ -893,8 +893,9 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid,
 int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath,
                          const char *namespace)
 {
+       __do_free char *dup = NULL;
        int fd, pid;
-       char *dup, *lastslash;
+       char *lastslash;
 
        if (nsfd_path[0] == '/') {
                return open(nsfd_path, O_RDONLY | O_CLOEXEC);
@@ -904,21 +905,20 @@ int lxc_inherit_namespace(const char *nsfd_path, const char *lxcpath,
        if (lastslash) {
                dup = strdup(nsfd_path);
                if (!dup)
-                       return -1;
+                       return ret_errno(ENOMEM);
 
                dup[lastslash - nsfd_path] = '\0';
-               pid = lxc_container_name_to_pid(lastslash + 1, dup);
-               free(dup);
-       } else {
-               pid = lxc_container_name_to_pid(nsfd_path, lxcpath);
+               lxcpath = lastslash + 1;
+               nsfd_path = lastslash + 1;
        }
 
+       pid = lxc_container_name_to_pid(nsfd_path, lxcpath);
        if (pid < 0)
-               return -1;
+               return pid;
 
        fd = lxc_preserve_ns(pid, namespace);
        if (fd < 0)
-               return -1;
+               return -errno;
 
        return fd;
 }
index 27b0fb7359e705a2c9ef1452657bf1a186c71765..06c4716349e44c1e5089541bf7364fc9b9cc4c05 100644 (file)
@@ -1372,10 +1372,8 @@ int lxc_preserve_ns(const int pid, const char *ns)
        ret = snprintf(path, __NS_PATH_LEN, "/proc/%d/ns%s%s", pid,
                       !ns || strcmp(ns, "") == 0 ? "" : "/",
                       !ns || strcmp(ns, "") == 0 ? "" : ns);
-       if (ret < 0 || (size_t)ret >= __NS_PATH_LEN) {
-               errno = EFBIG;
-               return -1;
-       }
+       if (ret < 0 || (size_t)ret >= __NS_PATH_LEN)
+               return ret_errno(EIO);
 
        return open(path, O_RDONLY | O_CLOEXEC);
 }