From: Serge Hallyn Date: Mon, 11 Mar 2024 20:41:05 +0000 (-0500) Subject: unshare: simplify lookup_name X-Git-Tag: v6.0.0~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=046b63cd20347f4b573df12475ca13be2ce62386;p=thirdparty%2Flxc.git 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 --- 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; }