Skip to content

Commit

Permalink
Fixes #982
Browse files Browse the repository at this point in the history
  • Loading branch information
d2weber committed Sep 10, 2024
1 parent cfc17ba commit 9a64ca2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ impl<'a> Socket<'a> {
// [...] the above constraints imply that 2 * the max window size must be less
// than 2**31 [...] Thus, the shift count must be limited to 14 (which allows
// windows of 2**30 = 1 Gbyte).
#[cfg(not(target_pointer_width = "16"))] // Prevent overflow
if rx_capacity > (1 << 30) {
panic!("receiving buffer too large, cannot exceed 1 GiB")
}
Expand Down Expand Up @@ -594,7 +595,7 @@ impl<'a> Socket<'a> {
fn scaled_window(&self) -> u16 {
cmp::min(
self.rx_buffer.window() >> self.remote_win_shift as usize,
(1 << 16) - 1,
u16::MAX as usize,
) as u16
}

Expand Down Expand Up @@ -1868,7 +1869,10 @@ impl<'a> Socket<'a> {
let assembler_was_empty = self.assembler.is_empty();

// Try adding payload octets to the assembler.
let Ok(contig_len) = self.assembler.add_then_remove_front(payload_offset, payload_len) else {
let Ok(contig_len) = self
.assembler
.add_then_remove_front(payload_offset, payload_len)
else {
net_debug!(
"assembler: too many holes to add {} octets at offset {}",
payload_len,
Expand Down Expand Up @@ -2155,7 +2159,7 @@ impl<'a> Socket<'a> {
State::SynSent | State::SynReceived => {
repr.control = TcpControl::Syn;
// window len must NOT be scaled in SYNs.
repr.window_len = self.rx_buffer.window().min((1 << 16) - 1) as u16;
repr.window_len = u16::try_from(self.rx_buffer.window()).unwrap_or(u16::MAX);
if self.state == State::SynSent {
repr.ack_number = None;
repr.window_scale = Some(self.remote_win_shift);
Expand Down

0 comments on commit 9a64ca2

Please sign in to comment.