From 046b63cd20347f4b573df12475ca13be2ce62386 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Mon, 11 Mar 2024 15:41:05 -0500 Subject: [PATCH] unshare: simplify lookup_name pass the optarg straight to getpwnam_r, instead of first scanning the name out of it. Signed-off-by: Serge Hallyn --- src/lxc/tools/lxc_unshare.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index 206c13146..cf331d30a 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -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; } -- 2.47.2