diff --git a/newlib/libc/posix/posix_spawn.c b/newlib/libc/posix/posix_spawn.c index 3506b0f8b..6fd6159d0 100644 --- a/newlib/libc/posix/posix_spawn.c +++ b/newlib/libc/posix/posix_spawn.c @@ -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));