summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorBhasker Hariharan <bhaskerh@google.com>2021-04-22 16:31:11 -0700
committergVisor bot <gvisor-bot@google.com>2021-04-22 16:34:00 -0700
commit2739cf46284f2786ad33b545d55b8178bc46f7de (patch)
tree45440f2d40f3eb885341e4a9709bdecf95d8a5c0 /test/syscalls/linux
parent0a6eaed50b83a35a687699aa5e871b80605c9f46 (diff)
Fix AF_UNIX listen() w/ zero backlog.
In https://github.com/google/gvisor/commit/f075522849fa a check to increase zero to a minimum backlog length was removed from sys_socket.go to bring it in parity with linux and then in tcp/endpoint.go we bump backlog by 1. But this broke calling listen on a AF_UNIX socket w/ a zero backlog as in linux it does allow 1 connection even with a zero backlog. This was caught by a php runtime test socket_abstract_path.phpt. PiperOrigin-RevId: 369974744
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/socket_unix_unbound_abstract.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket_unix_unbound_abstract.cc b/test/syscalls/linux/socket_unix_unbound_abstract.cc
index 8b1762000..dd3d25450 100644
--- a/test/syscalls/linux/socket_unix_unbound_abstract.cc
+++ b/test/syscalls/linux/socket_unix_unbound_abstract.cc
@@ -72,6 +72,52 @@ TEST_P(UnboundAbstractUnixSocketPairTest, BindNothing) {
SyscallSucceeds());
}
+TEST_P(UnboundAbstractUnixSocketPairTest, ListenZeroBacklog) {
+ SKIP_IF((GetParam().type & SOCK_DGRAM) != 0);
+ auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
+ struct sockaddr_un addr = {};
+ addr.sun_family = AF_UNIX;
+ constexpr char kPath[] = "\x00/foo_bar";
+ memcpy(addr.sun_path, kPath, sizeof(kPath));
+ ASSERT_THAT(bind(sockets->first_fd(),
+ reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)),
+ SyscallSucceeds());
+ ASSERT_THAT(listen(sockets->first_fd(), 0 /* backlog */), SyscallSucceeds());
+ ASSERT_THAT(connect(sockets->second_fd(),
+ reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)),
+ SyscallSucceeds());
+ auto sockets2 = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
+ {
+ // Set the FD to O_NONBLOCK.
+ int opts;
+ int orig_opts;
+ ASSERT_THAT(opts = fcntl(sockets2->first_fd(), F_GETFL), SyscallSucceeds());
+ orig_opts = opts;
+ opts |= O_NONBLOCK;
+ ASSERT_THAT(fcntl(sockets2->first_fd(), F_SETFL, opts), SyscallSucceeds());
+
+ ASSERT_THAT(
+ connect(sockets2->first_fd(), reinterpret_cast<struct sockaddr*>(&addr),
+ sizeof(addr)),
+ SyscallFailsWithErrno(EAGAIN));
+ }
+ {
+ // Set the FD to O_NONBLOCK.
+ int opts;
+ int orig_opts;
+ ASSERT_THAT(opts = fcntl(sockets2->second_fd(), F_GETFL),
+ SyscallSucceeds());
+ orig_opts = opts;
+ opts |= O_NONBLOCK;
+ ASSERT_THAT(fcntl(sockets2->second_fd(), F_SETFL, opts), SyscallSucceeds());
+
+ ASSERT_THAT(
+ connect(sockets2->second_fd(),
+ reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)),
+ SyscallFailsWithErrno(EAGAIN));
+ }
+}
+
TEST_P(UnboundAbstractUnixSocketPairTest, GetSockNameFullLength) {
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());