summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/socket_unix_stream.cc
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2021-09-01 11:46:02 -0700
committergVisor bot <gvisor-bot@google.com>2021-09-01 11:48:23 -0700
commit927ea16dd384f675a2ce1456be457a371109c488 (patch)
treed4131e5e5b84e0d6629259fd27793693656e8f1d /test/syscalls/linux/socket_unix_stream.cc
parent5e3a5189152e682f94c745a544993c26e18eb9a2 (diff)
unix: handle a case when a buffer is overflowed
Reported-by: syzbot+1aab6800bd14829609b8@syzkaller.appspotmail.com PiperOrigin-RevId: 394279838
Diffstat (limited to 'test/syscalls/linux/socket_unix_stream.cc')
-rw-r--r--test/syscalls/linux/socket_unix_stream.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket_unix_stream.cc b/test/syscalls/linux/socket_unix_stream.cc
index 6e9f70f8c..2f3cfc3f3 100644
--- a/test/syscalls/linux/socket_unix_stream.cc
+++ b/test/syscalls/linux/socket_unix_stream.cc
@@ -181,6 +181,21 @@ TEST_P(StreamUnixSocketPairTest, SetSocketSendBuf) {
ASSERT_EQ(quarter_sz, val);
}
+TEST_P(StreamUnixSocketPairTest, SendBufferOverflow) {
+ auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
+ auto s = sockets->first_fd();
+
+ constexpr int kBufSz = 4096;
+ std::vector<char> buf(kBufSz * 4);
+ ASSERT_THAT(RetryEINTR(send)(s, buf.data(), buf.size(), MSG_DONTWAIT),
+ SyscallSucceeds());
+ // The new buffer size should be smaller that the amount of data in the queue.
+ ASSERT_THAT(setsockopt(s, SOL_SOCKET, SO_SNDBUF, &kBufSz, sizeof(kBufSz)),
+ SyscallSucceeds());
+ ASSERT_THAT(RetryEINTR(send)(s, buf.data(), buf.size(), MSG_DONTWAIT),
+ SyscallFailsWithErrno(EAGAIN));
+}
+
TEST_P(StreamUnixSocketPairTest, IncreasedSocketSendBufUnblocksWrites) {
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
int sock = sockets->first_fd();