From nobody Thu Sep 11 18:50:23 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 4cN67h3wQZz67Hx7; Thu, 11 Sep 2025 18:50:24 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cN67g5pXKz3h2t; Thu, 11 Sep 2025 18:50:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757616623; 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=XvjwgStaM1cv75muIjGpQ4IXFqLYa/8cYVtlYbEQlSg=; b=mhLBA9RzCPgzd5g6X8brfMkZXypthbNl+ryrWyhTEtcFHHfsFRMZgxZ+C7vOp3lBamoIMX cWIvQrcic7ShQv/yx2ZPBttqf8263cmD+Lp+Bil52QzNf6iChpM7IEa8BWBe+bOEO3y9ka 2afdzNdWAeNXGYvqUoQagFzwS1YN+i6bV4/2U4KF1ASf347m1+EL9AN8uIhBzshzyX+IHZ IfGT0FJStW0JwxbePAGyVXPu3C6t/cqTem2wZw2pyqBx23PN3+N96NyHiyi3Ejc4DG9H3c YHvi5962147dGsL+/94ThXROlMVe2HIOxumnG1wowE6fyPuP3flvwyXOAP538w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757616623; 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=XvjwgStaM1cv75muIjGpQ4IXFqLYa/8cYVtlYbEQlSg=; b=X4mnThbZzR1iNjc1edvzsEgz+jzHtpT5LMWumWNSkwDEOredgR2Osa+FqFyKcNAVqtwhb4 hqWgbrsmSFemFPY+dsq+0MbwU/kv0YBBMYSGDhNADx31HnWZ6a+zFkcWkPkL37M4/Z8+CS ib15256S1NVwAUlF1CD9efGjIn2KuS+0LPLpFD+CWnmnTi2r9oDPYrmTMFJ4pKnU2XHX05 +2GWNt2ymX+BMCIoANzA6NQUT8GuZyRrNBt2qr1sKW30IFL2iN64vJvdKxePF7RyVe92a0 uGAPAhMTqAA1XiUk7YZSoU0xRb1newNu135gPdDpRA13F12oxz0QOTaH3XQ+OQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757616623; a=rsa-sha256; cv=none; b=NynuQpg+wU/Kh5WjuS+wVwiXhRnoVCYGjUQWXwezwI5u8QuIfUyCjk7Vm9QYsIxNFsHr62 JHnv/Bsg3qp9/VUQDhz5H/yy3WuL6yxOoO/5/ThCFYXTS3OpeiZMmlByXSpML7V2EVUAUl u33s6FkJlkx4UYjsZr40XGSyQhLaWxMMAlgm3bHWHx3PxpsWR7NYKwA+lshMmqCUHp/xxQ S535QhFC/TwrwsSQmqDsaKPegDuQP4saKox3/c2rtv37mmHZ8fh5UJkqs4OU8NtALIgxMY ozeINc2iOvrNTVabNJ2vJ/+axv6l/kG7ts456HnRIK4XC88OP7cjF9EskMDOlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cN67g5P8Xz4BR; Thu, 11 Sep 2025 18:50:23 +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 58BIoNL4092942; Thu, 11 Sep 2025 18:50:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58BIoNFl092939; Thu, 11 Sep 2025 18:50:23 GMT (envelope-from git) Date: Thu, 11 Sep 2025 18:50:23 GMT Message-Id: <202509111850.58BIoNFl092939@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 5e6d22fffb23 - stable/14 - flua: fbsd: avoid leaking stdin pipes on error 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5e6d22fffb23b94273a13a8b58d822596451e8a8 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=5e6d22fffb23b94273a13a8b58d822596451e8a8 commit 5e6d22fffb23b94273a13a8b58d822596451e8a8 Author: Kyle Evans AuthorDate: 2025-07-09 05:12:31 +0000 Commit: Ed Maste CommitDate: 2025-09-11 15:09:59 +0000 flua: fbsd: avoid leaking stdin pipes on error Additionally, there's no way to get to the end without a valid stdin_pipe[1] at the moment, so don't check for it. stdin_pipe[0] is closed earlier, as the parent shouldn't need the read-side of the pipe. While we're here, also free the file actions earlier and on error -- they're not necessary once posix_spawnp() has returned. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D50537 (cherry picked from commit 0610ba6cdbf2d8bed2619ae78ef2da5ee9c30b94) --- libexec/flua/modules/lfbsd.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libexec/flua/modules/lfbsd.c b/libexec/flua/modules/lfbsd.c index 30cafcc7309e..6279474f8388 100644 --- a/libexec/flua/modules/lfbsd.c +++ b/libexec/flua/modules/lfbsd.c @@ -88,13 +88,22 @@ lua_exec(lua_State *L) argv = luaL_checkarraystrings(L, 1); if (0 != (r = posix_spawnp(&pid, argv[0], &action, NULL, (char*const*)argv, environ))) { + close(stdin_pipe[0]); + close(stdin_pipe[1]); + posix_spawn_file_actions_destroy(&action); + lua_pushnil(L); lua_pushstring(L, strerror(r)); lua_pushinteger(L, r); return (3); } + + close(stdin_pipe[0]); + posix_spawn_file_actions_destroy(&action); + while (waitpid(pid, &pstat, 0) == -1) { if (errno != EINTR) { + close(stdin_pipe[1]); lua_pushnil(L); lua_pushstring(L, strerror(r)); lua_pushinteger(L, r); @@ -109,12 +118,7 @@ lua_exec(lua_State *L) return (3); } - posix_spawn_file_actions_destroy(&action); - - if (stdin_pipe[0] != -1) - close(stdin_pipe[0]); - if (stdin_pipe[1] != -1) - close(stdin_pipe[1]); + close(stdin_pipe[1]); lua_pushinteger(L, pid); return 1; }