From e1a2d79020f46b1409b14523a404eca6eb4b371a Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Wed, 16 Nov 2022 07:28:04 -0800 Subject: [PATCH] Don't hardcode ports when binding udp sockets The existing logic constructs a loopback address for binding by incrementing the port number of an existing address. This can lead to failures in the event that the original address had port=65535 (the maximum port). Resolve this failure case by using the same port number instead of incrementing. PiperOrigin-RevId: 488934780 --- test/syscalls/linux/udp_socket.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/syscalls/linux/udp_socket.cc b/test/syscalls/linux/udp_socket.cc index 89017775f..91746275a 100644 --- a/test/syscalls/linux/udp_socket.cc +++ b/test/syscalls/linux/udp_socket.cc @@ -1228,10 +1228,10 @@ TEST_P(UdpSocketTest, ReadShutdownSameSocketResetsShutdownState) { // Connect the socket, then try to shutdown again. ASSERT_NO_ERRNO(BindLoopback()); - // Connect to loopback:bind_addr_port+1. + // Connect `bind_` to itself since we know the port number is valid. struct sockaddr_storage addr_storage = InetLoopbackAddr(); struct sockaddr* addr = AsSockAddr(&addr_storage); - SetPort(&addr_storage, *Port(&bind_addr_storage_) + 1); + SetPort(&addr_storage, *Port(&bind_addr_storage_)); ASSERT_THAT(connect(bind_.get(), addr, addrlen_), SyscallSucceeds()); EXPECT_THAT(recv(bind_.get(), received, sizeof(received), MSG_DONTWAIT),