mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user