summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorNayana Bidari <nybidari@google.com>2020-03-02 16:30:51 -0800
committergVisor bot <gvisor-bot@google.com>2020-03-02 16:31:52 -0800
commit43abb24657e737dee1108ff0d512b2e1b6d8a3f6 (patch)
treeb217bfeb0656f0a4988432e581f0023234b6850b /test
parentd80b6a6e498fa9301250572a1abcfa68c5aaaa1c (diff)
Fix panic caused by invalid address for Bind in packet sockets.
PiperOrigin-RevId: 298476533
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/packet_socket.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/syscalls/linux/packet_socket.cc b/test/syscalls/linux/packet_socket.cc
index bc22de788..248762ca9 100644
--- a/test/syscalls/linux/packet_socket.cc
+++ b/test/syscalls/linux/packet_socket.cc
@@ -417,6 +417,19 @@ TEST_P(CookedPacketTest, BindDrop) {
EXPECT_THAT(RetryEINTR(poll)(&pfd, 1, 1000), SyscallSucceedsWithValue(0));
}
+// Bind with invalid address.
+TEST_P(CookedPacketTest, BindFail) {
+ // Null address.
+ ASSERT_THAT(bind(socket_, nullptr, sizeof(struct sockaddr)),
+ SyscallFailsWithErrno(EFAULT));
+
+ // Address of size 1.
+ uint8_t addr = 0;
+ ASSERT_THAT(
+ bind(socket_, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)),
+ SyscallFailsWithErrno(EINVAL));
+}
+
INSTANTIATE_TEST_SUITE_P(AllInetTests, CookedPacketTest,
::testing::Values(ETH_P_IP, ETH_P_ALL));