posix_spawn_file_actions_addfchdir_np: return EBADF on negative fd

FreeBSD and Musl implement posix_spawn_file_actions_addfchdir_np
so that it checks the incoming descriptor for being negative, and,
if so, return with EBADF.  The POSIX proposal defining
posix_spawn_file_actions_addfchdir follows this behaviour, see
https://www.austingroupbugs.net/view.php?id=1208

Fixes: 7e03fc35f5 ("Add posix_spawn_file_actions_add{f}chdir_np")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2023-04-19 20:48:14 +02:00
parent 53f7fb20a0
commit 3124d8b436
1 changed files with 6 additions and 1 deletions

View File

@ -565,7 +565,12 @@ posix_spawn_file_actions_addfchdir_np (
int fd)
{
posix_spawn_file_actions_entry_t *fae;
int error;
/* POSIX proposal documents it as implemented in FreeBSD and Musl.
Return EBADF if fd is negative.
https://www.austingroupbugs.net/view.php?id=1208 */
if (fd < 0)
return EBADF;
/* Allocate object */
fae = malloc(sizeof(posix_spawn_file_actions_entry_t));