Prevent printing binary in RPC errors (#1604)
## Issue Addressed #1566 ## Proposed Changes Prevents printing binary characters in the RPC error response from peers.
This commit is contained in:
parent
b19cf02d2d
commit
d79366c503
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1521,6 +1521,7 @@ dependencies = [
|
|||||||
"lru",
|
"lru",
|
||||||
"parking_lot 0.11.0",
|
"parking_lot 0.11.0",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"sha2 0.9.1",
|
"sha2 0.9.1",
|
||||||
|
@ -37,6 +37,7 @@ tiny-keccak = "2.0.2"
|
|||||||
environment = { path = "../../lighthouse/environment" }
|
environment = { path = "../../lighthouse/environment" }
|
||||||
# TODO: Remove rand crate for mainnet
|
# TODO: Remove rand crate for mainnet
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
|
regex = "1.3.9"
|
||||||
|
|
||||||
[dependencies.libp2p]
|
[dependencies.libp2p]
|
||||||
#version = "0.23.0"
|
#version = "0.23.0"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Available RPC methods types and ids.
|
//! Available RPC methods types and ids.
|
||||||
|
|
||||||
use crate::types::EnrBitfield;
|
use crate::types::EnrBitfield;
|
||||||
|
use regex::bytes::Regex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
use ssz_types::{
|
use ssz_types::{
|
||||||
@ -42,10 +43,9 @@ impl Deref for ErrorType {
|
|||||||
|
|
||||||
impl ToString for ErrorType {
|
impl ToString for ErrorType {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match std::str::from_utf8(self.0.deref()) {
|
#[allow(clippy::invalid_regex)]
|
||||||
Ok(s) => s.to_string(),
|
let re = Regex::new("\\p{C}").expect("Regex is valid");
|
||||||
Err(_) => format!("{:?}", self.0.deref()), // Display raw bytes if not a UTF-8 string
|
String::from_utf8_lossy(&re.replace_all(self.0.deref(), &b""[..])).to_string()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user