public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Ken Brown <kbrown@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: AF_LOCAL: set appropriate errno on system calls Date: Thu, 30 Jan 2020 14:44:00 -0000 [thread overview] Message-ID: <20200130144435.43081.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=141437d37440572b5452e941df3d4454f0c4378b commit 141437d37440572b5452e941df3d4454f0c4378b Author: Ken Brown <kbrown@cornell.edu> Date: Thu Jan 23 15:11:15 2020 -0500 Cygwin: AF_LOCAL: set appropriate errno on system calls If an AF_LOCAL socket is opened with O_PATH, all socket system calls that take a file descriptor argument fail on the resulting descriptor. Make sure that errno is set as on Linux for those calls that are implemented on Linux. In almost all cases it is ENOTSOCK. There are two exceptions: - sockatatmark(3); errno is EBADF. - bindresvport(3); errno is EAFNOSUPPORT if the second argument sin (of type struct sockaddr_in *) is non-NULL and satisfies sin->sin_family == AF_INET. Finally, there are two BSD socket system calls implemented on Cygwin but not Linux: getpeereid(3) and bindresvport_sa(3). Set errno to ENOTSOCK for these for consistency with the majority of the other calls. Diff: --- winsup/cygwin/net.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 437712c..d9f51bf 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -65,8 +65,11 @@ get (const int fd) fhandler_socket *const fh = cfd->is_socket (); - if (!fh) - set_errno (ENOTSOCK); + if (!fh || (fh->get_flags () & O_PATH)) + { + set_errno (ENOTSOCK); + return NULL; + } return fh; } @@ -641,9 +644,17 @@ extern "C" int sockatmark (int fd) { int ret; + cygheap_fdget cfd (fd); - fhandler_socket *fh = get (fd); - if (fh && fh->ioctl (SIOCATMARK, &ret) != -1) + if (cfd < 0) + return -1; + + fhandler_socket *const fh = cfd->is_socket (); + if (!fh) + set_errno (ENOTSOCK); + else if (fh->get_flags () & O_PATH) + set_errno (EBADF); + else if (fh->ioctl (SIOCATMARK, &ret) != -1) return ret; return -1; }
reply other threads:[~2020-01-30 14:44 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=20200130144435.43081.qmail@sourceware.org \ --to=kbrown@sourceware.org \ --cc=cygwin-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: linkBe 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).