From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 9097C3858D33; Wed, 19 Apr 2023 19:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9097C3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681931369; bh=ZzVhNXpOexHL1DltqNcioxj3ESkTCnlRz3eQ+jUOlJg=; h=From:To:Subject:Date:From; b=fUAaaE4PAzqnTt1PXpxcXTnn3GdpmLqNaOZgqb7neZCVB+TpWDJJdli4LvTR7ihhv /S0FlAIawmzEGyTsKZZKxakEqUGAfYh5+CRFS80sWAs6DWnxb4ALRM7+iY6qL1h+2T VDJtYzxFt07PHNatW/uNyNlYg2OZubXz/EhPNfhg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin/main] posix_spawn_file_actions_addfchdir_np: return EBADF on negative fd X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 53f7fb20a064fec180291a497d11eb66fe6172e6 X-Git-Newrev: 3124d8b436a8130130ffe9c6a397556ff0125e66 Message-Id: <20230419190929.9097C3858D33@sourceware.org> Date: Wed, 19 Apr 2023 19:09:29 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3124d8b436a= 8130130ffe9c6a397556ff0125e66 commit 3124d8b436a8130130ffe9c6a397556ff0125e66 Author: Corinna Vinschen AuthorDate: Wed Apr 19 20:48:14 2023 +0200 Commit: Corinna Vinschen CommitDate: Wed Apr 19 20:48:14 2023 +0200 posix_spawn_file_actions_addfchdir_np: return EBADF on negative fd =20 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=3D1208 =20 Fixes: 7e03fc35f528 ("Add posix_spawn_file_actions_add{f}chdir_np") Signed-off-by: Corinna Vinschen Diff: --- newlib/libc/posix/posix_spawn.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/newlib/libc/posix/posix_spawn.c b/newlib/libc/posix/posix_spaw= n.c index 3506b0f8bffe..6fd6159d054d 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=3D1208 */ + if (fd < 0) + return EBADF; =20 /* Allocate object */ fae =3D malloc(sizeof(posix_spawn_file_actions_entry_t));