From nobody Wed Jul 9 05:12:53 2025 X-Original-To: dev-commits-src-main@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 4bcR1x36gBz6172T; Wed, 09 Jul 2025 05:12:53 +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 4bcR1x1z8xz3LQ9; Wed, 09 Jul 2025 05:12:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752037973; 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=Y15FpRDnDqExAD4Oro7aCjPc3cPmv7ntDFrdomXqCmo=; b=s5ts5r6jyvrNzlJZfCHFLvDTRPzdja0u+D4xdbAkuUdGfzJ0ekqT/o6gbea4aZCF5NK+7L 1K30TTE9j8uB61WHCGlKwB2WREQqmd+2QRL/nsTqmzpb0kdQL9gK5u7OS/P5LRYEKCq7+8 xJMKJYz3fVG5A9aD3hFQcwW8shMHELb8kveYpN7jiqCgCul+CjqDNfLPpnoQSFeMnclUPK 9lXYobQwCk8VKa+h+uKz9lVlJ4Bjs81j+Q3MN9nq0X+cNUbbfm8kAi18N0iMbY5gi3a5zK ozSWRiDe8O6D9+VwXdFYF/p22Dz3oCOcM9m6cwYGgBTBuqR5FhA4O1SEC+sg/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752037973; 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=Y15FpRDnDqExAD4Oro7aCjPc3cPmv7ntDFrdomXqCmo=; b=x0tEvRjULKi/HHSdxwJCrluNtVg8EPW5Wug9vADoiSo221LPwkyEW2p9TcDfUO0xwpSGZx R8sNqSWJu22z6RaYXVSg6enpaREP6r+Wo9iXdlKpyN5+n7nKzn3J5Pdy2EIR61KO13tblF TfOYp+yhI7kpIezmmBK8ZJXkT80aiVXmBFaNC9udyl4XmPtMBmvYtK1m2hVORvB2giwghN z6chlQE2afZz2JinQGjyI9At8uo4R4Q0WAEZx3dsgWGu8urvC3J08YCM1mXhS3wAX7k1bu pIeYKjrg2+hH601HT6lYoMSIrtQcaX3XihbIXZFEg/ipr78+jYU78quVVuGRMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752037973; a=rsa-sha256; cv=none; b=Z/K/BYmfY1458EvM1nb7TI7yu1keW25lU2Rid9OZhCUdxiYKkq2jjdo7mqTn2nw/EyWx2g gxdPuwpWf+ybwgWx7TnuhyxUGloV9gYnQiayAcsSKwJC6A8R/0V4IUzWdVHwBmjQDvBr9G SktBSf9rTPL/QPfc9zjrud1h8VAXJnUca2s6H+FF2etkTZ/YE8H4UsrHZFq2VX84QC9maf M+UpVLigeFJy64tLTaDdubqNVwD3XoVQLFhoMLw2kEXgSRuUNa5Ynq+auo0VmufvdoTQQO kfazKIqwQc45opUB8BrZrJV+ICsggJIX/LUMo5pnk+Eq12c/FNSD5u6BRTRKRA== 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 4bcR1x1RD0z17KQ; Wed, 09 Jul 2025 05:12:53 +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 5695CrFN030455; Wed, 9 Jul 2025 05:12:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5695Crp0030452; Wed, 9 Jul 2025 05:12:53 GMT (envelope-from git) Date: Wed, 9 Jul 2025 05:12:53 GMT Message-Id: <202507090512.5695Crp0030452@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 0610ba6cdbf2 - main - flua: fbsd: avoid leaking stdin pipes on error List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0610ba6cdbf2d8bed2619ae78ef2da5ee9c30b94 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=0610ba6cdbf2d8bed2619ae78ef2da5ee9c30b94 commit 0610ba6cdbf2d8bed2619ae78ef2da5ee9c30b94 Author: Kyle Evans AuthorDate: 2025-07-09 05:12:31 +0000 Commit: Kyle Evans CommitDate: 2025-07-09 05:12:31 +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 --- 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; }