From 5347e4b72dd6a6eac50e95ba596ed53495c363ef Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 16 Oct 2023 10:47:29 +0200 Subject: [PATCH] fix: limit the number of peers to share Signed-off-by: ljedrz --- node/router/messages/src/peer_response.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/router/messages/src/peer_response.rs b/node/router/messages/src/peer_response.rs index 768311152c..6dfb373c83 100644 --- a/node/router/messages/src/peer_response.rs +++ b/node/router/messages/src/peer_response.rs @@ -33,8 +33,9 @@ impl MessageTrait for PeerResponse { /// Serializes the message into the buffer. #[inline] fn serialize(&self, writer: &mut W) -> Result<()> { + // Restrict the maximum number of peers to share. (self.peers.len().min(u8::MAX as usize) as u8).write_le(&mut *writer)?; - for peer in &self.peers { + for peer in self.peers.iter().take(u8::MAX as usize) { peer.write_le(&mut *writer)?; }