Skip to content

Commit

Permalink
Fix a debug assertion in Noise handshake when expected_len == 0 (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored May 29, 2022
1 parent 50545cd commit 7620746
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libp2p/connection/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ impl HandshakeInProgress {
// Decoding the first two bytes, which are the length of the handshake message.
let expected_len =
u16::from_be_bytes(<[u8; 2]>::try_from(&self.rx_buffer_encrypted[..2]).unwrap());
debug_assert!(self.rx_buffer_encrypted.len() < 2 + usize::from(expected_len));
debug_assert!(
expected_len == 0 || self.rx_buffer_encrypted.len() < 2 + usize::from(expected_len)
);

// Copy as much data as possible from `payload` to `self.rx_buffer_encrypted`, without
// copying more than the handshake message.
Expand Down

0 comments on commit 7620746

Please sign in to comment.