Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fixed panic on empty remote read request (#4619)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored Jan 14, 2020
1 parent 410ce11 commit 45995b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,13 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
who: PeerId,
request: message::RemoteReadRequest<B::Hash>,
) {
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::<String>(),
_ => format!(
Expand Down Expand Up @@ -1510,6 +1517,13 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
who: PeerId,
request: message::RemoteReadChildRequest<B::Hash>,
) {
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::<String>(),
_ => format!(
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/state/state_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ impl<Block, F, B, E, RA> StateBackend<B, E, Block, RA> for LightState<Block, F,
keys: Option<Vec<StorageKey>>
) {
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;
}
Expand Down

0 comments on commit 45995b4

Please sign in to comment.