From: Vladimir Fomene Date: Wed, 7 Jun 2023 04:48:28 +0000 (+0300) Subject: Use PrintableString for displaying errors in PeerManager X-Git-Tag: v0.0.116-alpha1~16^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b5c89cc977ecb593e282890aafd99ce0668136b8;p=rust-lightning Use PrintableString for displaying errors in PeerManager We currently just print "with non-ASCII error message" to log when we see non-ASCII chars, but should instead use our fancy PrintableString type to display the untrusted string and ignore control chars. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index a7f35a59c..2f569c52b 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -31,6 +31,7 @@ use crate::onion_message::{CustomOnionMessageContents, CustomOnionMessageHandler use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, NodeAlias}; use crate::util::atomic_counter::AtomicCounter; use crate::util::logger::Logger; +use crate::util::string::PrintableString; use crate::prelude::*; use crate::io; @@ -1536,38 +1537,14 @@ impl { - let mut data_is_printable = true; - for b in msg.data.bytes() { - if b < 32 || b > 126 { - data_is_printable = false; - break; - } - } - - if data_is_printable { - log_debug!(self.logger, "Got Err message from {}: {}", log_pubkey!(their_node_id), msg.data); - } else { - log_debug!(self.logger, "Got Err message from {} with non-ASCII error message", log_pubkey!(their_node_id)); - } + log_debug!(self.logger, "Got Err message from {}: {}", log_pubkey!(their_node_id), PrintableString(&msg.data)); self.message_handler.chan_handler.handle_error(&their_node_id, &msg); if msg.channel_id == [0; 32] { return Err(PeerHandleError { }.into()); } }, wire::Message::Warning(msg) => { - let mut data_is_printable = true; - for b in msg.data.bytes() { - if b < 32 || b > 126 { - data_is_printable = false; - break; - } - } - - if data_is_printable { - log_debug!(self.logger, "Got warning message from {}: {}", log_pubkey!(their_node_id), msg.data); - } else { - log_debug!(self.logger, "Got warning message from {} with non-ASCII error message", log_pubkey!(their_node_id)); - } + log_debug!(self.logger, "Got warning message from {}: {}", log_pubkey!(their_node_id), PrintableString(&msg.data)); }, wire::Message::Ping(msg) => {