]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
unshare: simplify lookup_name 4411/head
authorSerge Hallyn <serge@hallyn.com>
Mon, 11 Mar 2024 20:41:05 +0000 (15:41 -0500)
committerSerge Hallyn <serge@hallyn.com>
Mon, 11 Mar 2024 20:55:46 +0000 (15:55 -0500)
pass the optarg straight to getpwnam_r, instead of first
scanning the name out of it.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
src/lxc/tools/lxc_unshare.c

index 206c13146a69878d174c92f94f24b43ae1311182..cf331d30a2037560088438d3cac53be8538c12ef 100644 (file)
@@ -144,7 +144,6 @@ static int get_namespace_flags(char *namespaces)
 
 static bool lookup_user(const char *oparg, uid_t *uid)
 {
-       char name[PATH_MAX];
        struct passwd pwent;
        struct passwd *pwentp = NULL;
        char *buf;
@@ -164,17 +163,12 @@ static bool lookup_user(const char *oparg, uid_t *uid)
 
        if (sscanf(oparg, "%u", uid) < 1) {
                /* not a uid -- perhaps a username */
-               if (strlen(name) >= PATH_MAX || sscanf(oparg, "%s", name) < 1) {
-                       free(buf);
-                       return false;
-               }
-
-               ret = getpwnam_r(name, &pwent, buf, bufsize, &pwentp);
+               ret = getpwnam_r(oparg, &pwent, buf, bufsize, &pwentp);
                if (!pwentp) {
                        if (ret == 0)
                                SYSERROR("Could not find matched password record");
 
-                       SYSERROR("Invalid username \"%s\"", name);
+                       SYSERROR("Invalid username \"%s\"", oparg);
                        free(buf);
                        return false;
                }