Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FrameHeader::format write & up minimum rustls to 0.21.6 #391

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/handshake/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
11 changes: 8 additions & 3 deletions src/protocol/frame/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
}
}

Expand Down Expand Up @@ -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,
"
Expand All @@ -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
})
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/frame/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down