Skip to content

Commit f361026

Browse files
authored
Rollup merge of #123798 - tniessen:patch-1, r=workingjubilee
Avoid invalid socket address in length calculation This has no effect on the lengths of these constants, but since the IP address portion of the socket addresses was intentionally chosen to be the largest valid value, it seems appropriate to also use the largest valid value for the other components (as opposed to invalid values exceeding the possible ranges).
2 parents 0ab8cc1 + e1972c0 commit f361026

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/core/src/net/socket_addr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl fmt::Display for SocketAddrV4 {
591591
if f.precision().is_none() && f.width().is_none() {
592592
write!(f, "{}:{}", self.ip(), self.port())
593593
} else {
594-
const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65536";
594+
const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65535";
595595

596596
let mut buf = DisplayBuffer::<{ LONGEST_IPV4_SOCKET_ADDR.len() }>::new();
597597
// Buffer is long enough for the longest possible IPv4 socket address, so this should never fail.
@@ -621,7 +621,7 @@ impl fmt::Display for SocketAddrV6 {
621621
}
622622
} else {
623623
const LONGEST_IPV6_SOCKET_ADDR: &str =
624-
"[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967296]:65536";
624+
"[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967295]:65535";
625625

626626
let mut buf = DisplayBuffer::<{ LONGEST_IPV6_SOCKET_ADDR.len() }>::new();
627627
match self.scope_id() {

0 commit comments

Comments
 (0)