diff options
author | Ken Brown <kbrown@cornell.edu> | 2020-01-23 23:11:15 +0300 |
---|---|---|
committer | Ken Brown <kbrown@cornell.edu> | 2020-01-30 17:43:19 +0300 |
commit | 141437d37440572b5452e941df3d4454f0c4378b (patch) | |
tree | 3ab1eadd92a70e9583042a7ab95f95df091c2685 /winsup/cygwin/net.cc | |
parent | 3a2191653ac979f494aa2797942bd96414cedde8 (diff) |
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.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 437712c63..d9f51bf68 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; } |