Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
d2weber committed Sep 18, 2024
1 parent 2edea78 commit 92dbf79
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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 @@ -676,10 +677,7 @@ impl<'a> Socket<'a> {
/// Used in internal calculations as well as packet generation.
#[inline]
fn scaled_window(&self) -> u16 {
cmp::min(
self.rx_buffer.window() >> self.remote_win_shift as usize,
(1 << 16) - 1,
) as u16
u16::try_from(self.rx_buffer.window() >> self.remote_win_shift as usize).unwrap_or(u16::MAX)
}

/// Return the last window field value, including scaling according to RFC 1323.
Expand Down Expand Up @@ -2334,7 +2332,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 92dbf79

Please sign in to comment.