From dd5b6384712fb554bb6e291f2bbcdc9ec2f66554 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 30 Jan 2021 16:09:22 -0500 Subject: fail posix_spawn file_actions operations with negative fds these functions are specified to fail with EBADF on negative fd arguments. apart from close, they are also specified to fail if the value exceeds OPEN_MAX, but as written it is not clear that this imposes any requirement when OPEN_MAX is not defined, and it's undesirable to impose a dynamic limit (via setrlimit) here since the limit at the time of posix_spawn may be different from the limit at the time of setting up the file actions. this may require revisiting later. --- src/process/posix_spawn_file_actions_addfchdir.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/process/posix_spawn_file_actions_addfchdir.c') diff --git a/src/process/posix_spawn_file_actions_addfchdir.c b/src/process/posix_spawn_file_actions_addfchdir.c index 436c683d..e89ede8c 100644 --- a/src/process/posix_spawn_file_actions_addfchdir.c +++ b/src/process/posix_spawn_file_actions_addfchdir.c @@ -6,6 +6,7 @@ int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd) { + if (fd < 0) return EBADF; struct fdop *op = malloc(sizeof *op); if (!op) return ENOMEM; op->cmd = FDOP_FCHDIR; -- cgit v1.2.1