[PATCH v2] posix: Handle negative fds in spawn's addfchdir

Lucas Chollet lucas.chollet@free.fr
Thu Mar 26 08:23:48 GMT 2026


This patch makes `posix_spawn_file_actions_addfchdir` return EBADF on
negative file descriptors. This is mandated by POSIX.

Signed-off-by: Lucas Chollet <lucas.chollet@free.fr>
---
v2:
 - I used fd < 0 in place of !__spawn_valid_fd (fd)

 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..e851af1722 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 (fd < 0)
+    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