public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin/main] posix_spawn_file_actions_addfchdir_np: return EBADF on negative fd
Date: Wed, 19 Apr 2023 19:09:29 +0000 (GMT)	[thread overview]
Message-ID: <20230419190929.9097C3858D33@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3124d8b436a8130130ffe9c6a397556ff0125e66

commit 3124d8b436a8130130ffe9c6a397556ff0125e66
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Apr 19 20:48:14 2023 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Apr 19 20:48:14 2023 +0200

    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: 7e03fc35f528 ("Add posix_spawn_file_actions_add{f}chdir_np")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

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_spawn.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=1208 */
+	if (fd < 0)
+		return EBADF;
 
 	/* Allocate object */
 	fae = malloc(sizeof(posix_spawn_file_actions_entry_t));

                 reply	other threads:[~2023-04-19 19:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230419190929.9097C3858D33@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).