[PATCH] posix: Handle negative fds in spawn's addfchdir
Lucas Chollet
lucas.chollet@free.fr
Wed Mar 25 14:04:51 GMT 2026
Hello all,
This is my first contribution here, so I hope I got everything right.
I tested this patch on my Linux x86_64 machine with `make check` and
got no regressions compared to master.
8<
This patch makes `posix_spawn_file_actions_addfchdir` return EBADF on
negative file descriptors. This is mandated by POSIX and similar to what
is already done in addopen/addclose.
Signed-off-by: Lucas Chollet <lucas.chollet@free.fr>
---
posix/spawn_faction_addfchdir.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/posix/spawn_faction_addfchdir.c b/posix/spawn_faction_addfchdir.c
index a3df6df489..b51139a61f 100644
--- a/posix/spawn_faction_addfchdir.c
+++ b/posix/spawn_faction_addfchdir.c
@@ -28,6 +28,9 @@ posix_spawn_file_actions_addfchdir_np (posix_spawn_file_actions_t *actions,
{
struct __spawn_action *rec;
+ if (!__spawn_valid_fd (fd))
+ return EBADF;
+
/* Allocate more memory if needed. */
if (actions->__used == actions->__allocated
&& __posix_spawn_file_actions_realloc (actions) != 0)
--
2.51.0
More information about the Libc-alpha
mailing list