Fix FrameHeader::format write & other lints

This commit is contained in:
Alex Butler 2023-12-01 22:49:23 +00:00 committed by Daniel Abramov
parent fc17f7341d
commit 0f6e6517e6
5 changed files with 18 additions and 10 deletions

View File

@ -1,5 +1,8 @@
# 0.20.1
# Unreleased (0.20.2)
- Improve `FrameHeader::format` write correctness.
- Up minimum _rustls_ to `0.21.6`.
# 0.20.1
- Fixes [CVE-2023-43669](https://github.com/snapview/tungstenite-rs/pull/379).
# 0.20.0

View File

@ -46,7 +46,7 @@ version = "0.2.3"
[dependencies.rustls]
optional = true
version = "0.21.0"
version = "0.21.6"
[dependencies.rustls-native-certs]
optional = true

View File

@ -167,10 +167,10 @@ impl AttackCheck {
return Err(Error::AttackAttempt);
}
if self.number_of_packets > MIN_PACKET_CHECK_THRESHOLD {
if self.number_of_packets * MIN_PACKET_SIZE > self.number_of_bytes {
return Err(Error::AttackAttempt);
}
if self.number_of_packets > MIN_PACKET_CHECK_THRESHOLD
&& self.number_of_packets * MIN_PACKET_SIZE > self.number_of_bytes
{
return Err(Error::AttackAttempt);
}
Ok(())

View File

@ -109,10 +109,10 @@ impl FrameHeader {
match lenfmt {
LengthFormat::U8(_) => (),
LengthFormat::U16 => {
output.write(&(length as u16).to_be_bytes())?;
output.write_all(&(length as u16).to_be_bytes())?;
}
LengthFormat::U64 => {
output.write(&length.to_be_bytes())?;
output.write_all(&length.to_be_bytes())?;
}
}
@ -370,6 +370,8 @@ impl Frame {
impl fmt::Display for Frame {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::fmt::Write;
write!(
f,
"
@ -389,7 +391,10 @@ payload: 0x{}
// self.mask.map(|mask| format!("{:?}", mask)).unwrap_or("NONE".into()),
self.len(),
self.payload.len(),
self.payload.iter().map(|byte| format!("{:02x}", byte)).collect::<String>()
self.payload.iter().fold(String::new(), |mut output, byte| {
_ = write!(output, "{byte:02x}");
output
})
)
}
}

View File

@ -48,7 +48,7 @@ mod tests {
#[test]
fn test_apply_mask() {
let mask = [0x6d, 0xb6, 0xb2, 0x80];
let unmasked = vec![
let unmasked = [
0xf3, 0x00, 0x01, 0x02, 0x03, 0x80, 0x81, 0x82, 0xff, 0xfe, 0x00, 0x17, 0x74, 0xf9,
0x12, 0x03,
];