From 8b4f3afa42f308a43b15f12444bf6aa856a08fde Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Sat, 9 Mar 2024 19:56:34 +0000 Subject: [PATCH] Update handshake deserialize to error on wrong messages --- crates/peer_binary_protocol/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/peer_binary_protocol/src/lib.rs b/crates/peer_binary_protocol/src/lib.rs index 97e6dcc..2a5f09b 100644 --- a/crates/peer_binary_protocol/src/lib.rs +++ b/crates/peer_binary_protocol/src/lib.rs @@ -524,6 +524,13 @@ impl Handshake> { let pstr_len = *b .first() .ok_or(MessageDeserializeError::NotEnoughData(1, "handshake"))?; + if pstr_len as usize != PSTR_BT1.len() { + return Err(MessageDeserializeError::Other(anyhow::anyhow!( + "pstr should be {} bytes long, but received {}", + PSTR_BT1.len(), + pstr_len + ))); + } let expected_len = 1usize + pstr_len as usize + 48; let hbuf = b .get(..expected_len)