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 a panic if Noise frame length is too low #2321

Merged
merged 4 commits into from
May 29, 2022
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
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- The networking code has been considerably refactored. Due to the large size of the change it is possible that unintended changes in behaviour have been introduced. ([#2264](https://github.com/paritytech/smoldot/pull/2264))

### Fixed

- Fix a panic in case of a Noise message with an invalid length. ([#2321](https://github.com/paritytech/smoldot/pull/2321))

## 0.6.16 - 2022-05-16

### Added
Expand Down
5 changes: 4 additions & 1 deletion src/libp2p/connection/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,12 @@ impl Noise {
// Allocate the space to decode to.
// Each frame consists of the payload plus 16 bytes of authentication data, therefore
// the payload size is `expected_len - 16`.
// We use `saturating_sub` in order to avoid panicking in case the `expected_len` is
// invalid. An invalid `expected_len` should trigger an error when decoding the
// message below.
let len_before = self.rx_buffer_decrypted.len();
self.rx_buffer_decrypted
.resize(len_before + expected_len - 16, 0);
.resize(len_before + expected_len.saturating_sub(16), 0);

// Finally decoding the data.
let written = self
Expand Down