Sanity test that open(2) on a UDS fails

Spoiler alert: it doesn't.

PiperOrigin-RevId: 272513529
This commit is contained in:
Michael Pratt
2019-10-02 14:01:49 -07:00
committed by gVisor bot
parent 2016cc283c
commit 61e40819d9
3 changed files with 27 additions and 0 deletions
+1
View File
@@ -333,6 +333,7 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_test_util",
"//test/util:file_descriptor",
"//test/util:test_main",
"//test/util:test_util",
"@com_google_googletest//:gtest",
+24
View File
@@ -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
+2
View File
@@ -83,6 +83,8 @@ inline ssize_t SendFd(int fd, void* buf, size_t count, int flags) {
count);
}
PosixErrorOr<struct sockaddr_un> UniqueUnixAddr(bool abstract, int domain);
// A Creator<T> is a function that attempts to create and return a new T. (This
// is copy/pasted from cloud/gvisor/api/sandbox_util.h and is just duplicated
// here for clarity.)