From 45995b4b7d0f995e51e6c04dac20f0effba2f65e Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 14 Jan 2020 18:49:46 +0300 Subject: [PATCH] fixed panic on empty remote read request (#4619) --- client/network/src/protocol.rs | 14 ++++++++++++++ client/rpc/src/state/state_light.rs | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index b712ebe515512..2aa29ea2793e3 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -1472,6 +1472,13 @@ impl, H: ExHashT> Protocol { who: PeerId, request: message::RemoteReadRequest, ) { + if request.keys.is_empty() { + debug!(target: "sync", "Invalid remote read request sent by {}", who); + self.behaviour.disconnect_peer(&who); + self.peerset_handle.report_peer(who, rep::BAD_MESSAGE); + return; + } + let keys_str = || match request.keys.len() { 1 => request.keys[0].to_hex::(), _ => format!( @@ -1510,6 +1517,13 @@ impl, H: ExHashT> Protocol { who: PeerId, request: message::RemoteReadChildRequest, ) { + if request.keys.is_empty() { + debug!(target: "sync", "Invalid remote child read request sent by {}", who); + self.behaviour.disconnect_peer(&who); + self.peerset_handle.report_peer(who, rep::BAD_MESSAGE); + return; + } + let keys_str = || match request.keys.len() { 1 => request.keys[0].to_hex::(), _ => format!( diff --git a/client/rpc/src/state/state_light.rs b/client/rpc/src/state/state_light.rs index abf4631bb82eb..482eb0723ff80 100644 --- a/client/rpc/src/state/state_light.rs +++ b/client/rpc/src/state/state_light.rs @@ -325,8 +325,8 @@ impl StateBackend for LightState> ) { let keys = match keys { - Some(keys) => keys, - None => { + Some(keys) if !keys.is_empty() => keys, + _ => { warn!("Cannot subscribe to all keys on light client. Subscription rejected."); return; }