From nobody Tue Jul 29 12:49:07 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4brwC75cSFz62xSr; Tue, 29 Jul 2025 12:49:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4brwC72x1mz3lBw; Tue, 29 Jul 2025 12:49:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753793347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=421g4m5ZJfF70pZesdQLNvZsLd16Dq7FpZGtNyBcGz0=; b=blvGMp+6a0LGfaqHO754LogxfylajkkjNtJEAwZnzqNDIBn8wJQZZg2D4HvwXtrYTaV5XE YKXul9nB4Pkff6wUGInCWlK0l2peBEDdvP5yJhQX3goaiU0ybtflfbW0opbG0M59hbj/5W Th9Dumfe5lmsRC9ZRFYBNDtmV5tnAvv7dXu/D0nSX7eV+4Dhc0McVZt+/zCM6xthMT27dc Z6TD6PBCajWlO1GgpLPf++8bLf6tJAX6a3+29l0u+UcDpFF5Vw0FWL/or502uNXVcwOJkn GKxtVZ+gHXeKSziUuNX+sMl1uEmIu+xfKXuQLur3kxC2Ale2WfEyVtrVrdgDlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753793347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=421g4m5ZJfF70pZesdQLNvZsLd16Dq7FpZGtNyBcGz0=; b=GXsKaJOvq9eCcYrHwGVOqW+2hDzvhMa/QkWCObe3c1X/+XTBkejBCztWXTtIlxuAyXnrgA y1arbovVs8X1NiNFNhL2/hwbCzDn7Mx60zFSkk4F8Hio7hMV183zJOSOO+4hr9VfpZSz/4 a/093jjQq7V9zdmevu+J+oqvoEbALSKcBkq9bICB87CgcKuOoIawFByYrdS5KQcamz4QVE k0VNduqCkgqbfSI22GhErzZmveMDZB1mK+gQduKTlQJFm+W3ICs/BabXkMaiS73CZNjh4w 7Xv75sh/u9CQjpCGmQcQRJTikJdostsXzWtglplMLMWecBscqbTx0j9M2Oz1TA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753793347; a=rsa-sha256; cv=none; b=PdmWEplI1JVu84aSLnVgtHXdXccRvrEJDXNtr0RwxqGYwxtC4pe+OE0Ydw05fe2GhLzeb4 kBHqfsLD6VUaPj1IeB/SZtbJWXXRGPh46ZsWkwokrNT0w0FviYqLlvKaKAZQAKXGSGyvxS n3h/vm6YaLgaYbbrrJbjL0QP4CP3j392Tyj6Ldzpt5GXLTusOG48uuH9x6s8zqmKX7zNxT EIXmGNGvXDPqLS+1+mEuwud+xX07W8mNnV1IwoOqoNos1AkJxL9zJeQvl9KCZGOv7OLo5g 22sFfnKwFuS9g0+ZagdyUZlInitNSVo+nfweFusrAO9kUPkTPV/des6V9LKm2g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4brwC726VHzXq2; Tue, 29 Jul 2025 12:49:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56TCn73e033464; Tue, 29 Jul 2025 12:49:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56TCn7xb033461; Tue, 29 Jul 2025 12:49:07 GMT (envelope-from git) Date: Tue, 29 Jul 2025 12:49:07 GMT Message-Id: <202507291249.56TCn7xb033461@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: cd0359507027 - stable/14 - lposix: Use reentrant passwd and group lookup functions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: cd03595070272fa97b0f3c9ca78e9d828918580b Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cd03595070272fa97b0f3c9ca78e9d828918580b commit cd03595070272fa97b0f3c9ca78e9d828918580b Author: Mark Johnston AuthorDate: 2025-07-04 19:06:10 +0000 Commit: Mark Johnston CommitDate: 2025-07-29 12:08:32 +0000 lposix: Use reentrant passwd and group lookup functions The implementation of chown() in the posix module handles user and group names as well as numeric IDs. When resolving names, be sure to use reentrant lookup functions rather than assuming it's safe to clobber the internal buffers used by getpwnam() and getgrnam(). Fix some style nits while here. Reviewed by: imp, bapt MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46555 (cherry picked from commit 88d94ead7f7cfb7ea7c4134b4cd2f89da670a8e1) --- libexec/flua/modules/lposix.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c index fa3fd5f8e589..bc55f35a942a 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -68,19 +68,24 @@ lua_chown(lua_State *L) { int n; const char *path; - uid_t owner = (uid_t) -1; - gid_t group = (gid_t) -1; + uid_t owner = (uid_t)-1; + gid_t group = (gid_t)-1; + int error; n = lua_gettop(L); luaL_argcheck(L, n > 1, n, "chown takes at least two arguments"); path = luaL_checkstring(L, 1); if (lua_isinteger(L, 2)) - owner = (uid_t) lua_tointeger(L, 2); + owner = (uid_t)lua_tointeger(L, 2); else if (lua_isstring(L, 2)) { - struct passwd *p = getpwnam(lua_tostring(L, 2)); - if (p != NULL) - owner = p->pw_uid; + char buf[4096]; + struct passwd passwd, *pwd; + + error = getpwnam_r(lua_tostring(L, 2), &passwd, + buf, sizeof(buf), &pwd); + if (error == 0) + owner = pwd->pw_uid; else return (luaL_argerror(L, 2, lua_pushfstring(L, "unknown user %s", @@ -93,11 +98,15 @@ lua_chown(lua_State *L) } if (lua_isinteger(L, 3)) - group = (gid_t) lua_tointeger(L, 3); + group = (gid_t)lua_tointeger(L, 3); else if (lua_isstring(L, 3)) { - struct group *g = getgrnam(lua_tostring(L, 3)); - if (g != NULL) - group = g->gr_gid; + char buf[4096]; + struct group gr, *grp; + + error = getgrnam_r(lua_tostring(L, 3), &gr, buf, sizeof(buf), + &grp); + if (error == 0) + group = grp->gr_gid; else return (luaL_argerror(L, 3, lua_pushfstring(L, "unknown group %s",