git: 5e6d22fffb23 - stable/14 - flua: fbsd: avoid leaking stdin pipes on error
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 11 Sep 2025 18:50:23 UTC
The branch stable/14 has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=5e6d22fffb23b94273a13a8b58d822596451e8a8
commit 5e6d22fffb23b94273a13a8b58d822596451e8a8
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-07-09 05:12:31 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
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;
}