mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
Avoid invalid socket address in length calculation
This commit is contained in:
parent
62cffeedcf
commit
e1972c0061
@ -591,7 +591,7 @@ impl fmt::Display for SocketAddrV4 {
|
|||||||
if f.precision().is_none() && f.width().is_none() {
|
if f.precision().is_none() && f.width().is_none() {
|
||||||
write!(f, "{}:{}", self.ip(), self.port())
|
write!(f, "{}:{}", self.ip(), self.port())
|
||||||
} else {
|
} 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();
|
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.
|
// 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 {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const LONGEST_IPV6_SOCKET_ADDR: &str =
|
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();
|
let mut buf = DisplayBuffer::<{ LONGEST_IPV6_SOCKET_ADDR.len() }>::new();
|
||||||
match self.scope_id() {
|
match self.scope_id() {
|
||||||
|
Loading…
Reference in New Issue
Block a user