summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/socket_unix.cc
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-12-12 11:07:25 -0800
committergVisor bot <gvisor-bot@google.com>2019-12-12 11:08:56 -0800
commit378d6c1f3697b8b939e6632e980562bfc8fb2781 (patch)
tree36047dc720fcc6f5b79c2cc230510a8779e00ca3 /test/syscalls/linux/socket_unix.cc
parentb9aa62b9f907e8de5244ac7cdb518960faafa307 (diff)
unix: allow to bind unix sockets only to AF_UNIX addresses
Reported-by: syzbot+2c0bcfd87fb4e8b7b009@syzkaller.appspotmail.com PiperOrigin-RevId: 285228312
Diffstat (limited to 'test/syscalls/linux/socket_unix.cc')
-rw-r--r--test/syscalls/linux/socket_unix.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket_unix.cc b/test/syscalls/linux/socket_unix.cc
index 8a28202a8..4cf1f76f1 100644
--- a/test/syscalls/linux/socket_unix.cc
+++ b/test/syscalls/linux/socket_unix.cc
@@ -65,6 +65,21 @@ TEST_P(UnixSocketPairTest, BindToBadName) {
SyscallFailsWithErrno(ENOENT));
}
+TEST_P(UnixSocketPairTest, BindToBadFamily) {
+ auto pair =
+ ASSERT_NO_ERRNO_AND_VALUE(UnixDomainSocketPair(SOCK_SEQPACKET).Create());
+
+ constexpr char kBadName[] = "/some/path/that/does/not/exist";
+ sockaddr_un sockaddr;
+ sockaddr.sun_family = AF_INET;
+ memcpy(sockaddr.sun_path, kBadName, sizeof(kBadName));
+
+ EXPECT_THAT(
+ bind(pair->first_fd(), reinterpret_cast<struct sockaddr*>(&sockaddr),
+ sizeof(sockaddr)),
+ SyscallFailsWithErrno(EINVAL));
+}
+
TEST_P(UnixSocketPairTest, RecvmmsgTimeoutAfterRecv) {
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
char sent_data[10];