Skip to content

Commit

Permalink
Avoid invalid socket address in length calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen committed Apr 11, 2024
1 parent 62cffee commit e1972c0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/net/socket_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl fmt::Display for SocketAddrV4 {
if f.precision().is_none() && f.width().is_none() {
write!(f, "{}:{}", self.ip(), self.port())
} else {
const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65536";
const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65535";

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

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

0 comments on commit e1972c0

Please sign in to comment.