diff options
author | Ghanan Gowripalan <ghanan@google.com> | 2020-11-06 01:45:12 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-06 01:47:09 -0800 |
commit | 955e09dfbdb8a4cdae0a0b625001a567f6f15758 (patch) | |
tree | 4ebc8738e46499ed05634881876a3e1b552d71bb /test | |
parent | 29683f359822310d0f81a5c0f6ccaf98d6c284a3 (diff) |
Do not send to the zero port
Port 0 is not meant to identify any remote port so attempting to send
a packet to it should return an error.
PiperOrigin-RevId: 341009528
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/udp_socket.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/syscalls/linux/udp_socket.cc b/test/syscalls/linux/udp_socket.cc index bc5bd9218..d65275fd3 100644 --- a/test/syscalls/linux/udp_socket.cc +++ b/test/syscalls/linux/udp_socket.cc @@ -1887,6 +1887,22 @@ TEST_P(UdpSocketTest, GetSocketDetachFilter) { SyscallFailsWithErrno(ENOPROTOOPT)); } +TEST_P(UdpSocketTest, SendToZeroPort) { + char buf[8]; + struct sockaddr_storage addr = InetLoopbackAddr(); + + // Sending to an invalid port should fail. + SetPort(&addr, 0); + EXPECT_THAT(sendto(sock_.get(), buf, sizeof(buf), 0, + reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)), + SyscallFailsWithErrno(EINVAL)); + + SetPort(&addr, 1234); + EXPECT_THAT(sendto(sock_.get(), buf, sizeof(buf), 0, + reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)), + SyscallSucceedsWithValue(sizeof(buf))); +} + INSTANTIATE_TEST_SUITE_P(AllInetTests, UdpSocketTest, ::testing::Values(AddressFamily::kIpv4, AddressFamily::kIpv6, |