diff options
author | Michael Pratt <mpratt@google.com> | 2019-10-02 14:00:32 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-10-02 14:01:49 -0700 |
commit | 61e40819d9db05aecb8b36a46d529bd8fe425dcf (patch) | |
tree | f8fb8a81fb72adc12948768b46120688399c44f0 /test/syscalls/linux/socket.cc | |
parent | 2016cc283cbdfc1a49cca86f6c160724ee4d0cbd (diff) |
Sanity test that open(2) on a UDS fails
Spoiler alert: it doesn't.
PiperOrigin-RevId: 272513529
Diffstat (limited to 'test/syscalls/linux/socket.cc')
-rw-r--r-- | test/syscalls/linux/socket.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket.cc b/test/syscalls/linux/socket.cc index caae215b8..3a07ac8d2 100644 --- a/test/syscalls/linux/socket.cc +++ b/test/syscalls/linux/socket.cc @@ -17,6 +17,7 @@ #include "gtest/gtest.h" #include "test/syscalls/linux/socket_test_util.h" +#include "test/util/file_descriptor.h" #include "test/util/test_util.h" namespace gvisor { @@ -57,5 +58,28 @@ TEST(SocketTest, ProtocolInet) { } } +using SocketOpenTest = ::testing::TestWithParam<int>; + +// UDS cannot be opened. +TEST_P(SocketOpenTest, Unix) { + // FIXME(b/142001530): Open incorrectly succeeds on gVisor. + SKIP_IF(IsRunningOnGvisor()); + + FileDescriptor bound = + ASSERT_NO_ERRNO_AND_VALUE(Socket(AF_UNIX, SOCK_STREAM, PF_UNIX)); + + struct sockaddr_un addr = + ASSERT_NO_ERRNO_AND_VALUE(UniqueUnixAddr(/*abstract=*/false, AF_UNIX)); + + ASSERT_THAT(bind(bound.get(), reinterpret_cast<struct sockaddr*>(&addr), + sizeof(addr)), + SyscallSucceeds()); + + EXPECT_THAT(open(addr.sun_path, GetParam()), SyscallFailsWithErrno(ENXIO)); +} + +INSTANTIATE_TEST_SUITE_P(OpenModes, SocketOpenTest, + ::testing::Values(O_RDONLY, O_RDWR)); + } // namespace testing } // namespace gvisor |