Skip to content

Commit 315fdf6

Browse files
committed
rename SanitizedString to UntrustedString
1 parent 86fd733 commit 315fdf6

8 files changed

+23
-23
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::util::events::{Event, EventHandler, EventsProvider, MessageSendEvent,
5959
use crate::util::events;
6060
use crate::util::wakers::{Future, Notifier};
6161
use crate::util::scid_utils::fake_scid;
62-
use crate::util::string::SanitizedString;
62+
use crate::util::string::UntrustedString;
6363
use crate::util::ser::{BigSize, FixedLengthReader, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter};
6464
use crate::util::logger::{Level, Logger};
6565
use crate::util::errors::APIError;
@@ -1991,7 +1991,7 @@ where
19911991
let peer_state = &mut *peer_state_lock;
19921992
if let hash_map::Entry::Occupied(chan) = peer_state.channel_by_id.entry(channel_id.clone()) {
19931993
if let Some(peer_msg) = peer_msg {
1994-
self.issue_channel_close_events(chan.get(),ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString(peer_msg.to_string()) });
1994+
self.issue_channel_close_events(chan.get(),ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(peer_msg.to_string()) });
19951995
} else {
19961996
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
19971997
}

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::util::test_utils;
3434
use crate::util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination};
3535
use crate::util::errors::APIError;
3636
use crate::util::ser::{Writeable, ReadableArgs};
37-
use crate::util::string::SanitizedString;
37+
use crate::util::string::UntrustedString;
3838
use crate::util::config::UserConfig;
3939

4040
use bitcoin::hash_types::BlockHash;
@@ -8345,7 +8345,7 @@ fn test_pre_lockin_no_chan_closed_update() {
83458345
let channel_id = crate::chain::transaction::OutPoint { txid: funding_created_msg.funding_txid, index: funding_created_msg.funding_output_index }.to_channel_id();
83468346
nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id, data: "Hi".to_owned() });
83478347
assert!(nodes[0].chain_monitor.added_monitors.lock().unwrap().is_empty());
8348-
check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString("Hi".to_string()) }, true);
8348+
check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString("Hi".to_string()) }, true);
83498349
}
83508350

83518351
#[test]
@@ -8803,7 +8803,7 @@ fn test_error_chans_closed() {
88038803
nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: chan_2.2, data: "ERR".to_owned() });
88048804
check_added_monitors!(nodes[0], 1);
88058805
check_closed_broadcast!(nodes[0], false);
8806-
check_closed_event!(nodes[0], 1, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString("ERR".to_string()) });
8806+
check_closed_event!(nodes[0], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString("ERR".to_string()) });
88078807
assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0).len(), 1);
88088808
assert_eq!(nodes[0].node.list_usable_channels().len(), 2);
88098809
assert!(nodes[0].node.list_usable_channels()[0].channel_id == chan_1.2 || nodes[0].node.list_usable_channels()[1].channel_id == chan_1.2);
@@ -8813,7 +8813,7 @@ fn test_error_chans_closed() {
88138813
let _chan_4 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
88148814
nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: [0; 32], data: "ERR".to_owned() });
88158815
check_added_monitors!(nodes[0], 2);
8816-
check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString("ERR".to_string()) });
8816+
check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString("ERR".to_string()) });
88178817
let events = nodes[0].node.get_and_clear_pending_msg_events();
88188818
assert_eq!(events.len(), 2);
88198819
match events[0] {

lightning/src/ln/payment_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::util::events::{ClosureReason, Event, HTLCDestination, MessageSendEven
2828
use crate::util::test_utils;
2929
use crate::util::errors::APIError;
3030
use crate::util::ser::Writeable;
31-
use crate::util::string::SanitizedString;
31+
use crate::util::string::UntrustedString;
3232

3333
use bitcoin::{Block, BlockHeader, TxMerkleNode};
3434
use bitcoin::hashes::Hash;
@@ -354,7 +354,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
354354
MessageSendEvent::HandleError { node_id, action: msgs::ErrorAction::SendErrorMessage { ref msg } } => {
355355
assert_eq!(node_id, nodes[1].node.get_our_node_id());
356356
nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), msg);
357-
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
357+
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
358358
check_added_monitors!(nodes[1], 1);
359359
assert_eq!(nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0).len(), 1);
360360
},
@@ -519,7 +519,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) {
519519
MessageSendEvent::HandleError { node_id, action: msgs::ErrorAction::SendErrorMessage { ref msg } } => {
520520
assert_eq!(node_id, nodes[1].node.get_our_node_id());
521521
nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), msg);
522-
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
522+
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
523523
check_added_monitors!(nodes[1], 1);
524524
bs_commitment_tx = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
525525
},

lightning/src/ln/reload_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::util::errors::APIError;
2323
use crate::util::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider};
2424
use crate::util::ser::{Writeable, ReadableArgs};
2525
use crate::util::config::UserConfig;
26-
use crate::util::string::SanitizedString;
26+
use crate::util::string::UntrustedString;
2727

2828
use bitcoin::hash_types::BlockHash;
2929

@@ -567,7 +567,7 @@ fn do_test_data_loss_protect(reconnect_panicing: bool) {
567567
nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), &err_msgs_0[0]);
568568
assert!(nodes[1].node.list_usable_channels().is_empty());
569569
check_added_monitors!(nodes[1], 1);
570-
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
570+
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
571571
check_closed_broadcast!(nodes[1], false);
572572
}
573573

lightning/src/ln/reorg_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ln::msgs::{ChannelMessageHandler, Init};
1717
use crate::util::events::{Event, MessageSendEventsProvider, ClosureReason, HTLCDestination};
1818
use crate::util::test_utils;
1919
use crate::util::ser::Writeable;
20-
use crate::util::string::SanitizedString;
20+
use crate::util::string::UntrustedString;
2121

2222
use bitcoin::blockdata::block::{Block, BlockHeader};
2323
use bitcoin::blockdata::script::Builder;
@@ -369,7 +369,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_
369369
nodes[0].node.test_process_background_events(); // Required to free the pending background monitor update
370370
check_added_monitors!(nodes[0], 1);
371371
let expected_err = "Funding transaction was un-confirmed. Locked at 6 confs, now have 0 confs.";
372-
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString(format!("Channel closed because of an exception: {}", expected_err)) });
372+
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Channel closed because of an exception: {}", expected_err)) });
373373
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: expected_err.to_owned() });
374374
assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
375375
nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clear();

lightning/src/ln/shutdown_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::util::test_utils::OnGetShutdownScriptpubkey;
2121
use crate::util::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
2222
use crate::util::errors::APIError;
2323
use crate::util::config::UserConfig;
24-
use crate::util::string::SanitizedString;
24+
use crate::util::string::UntrustedString;
2525

2626
use bitcoin::blockdata::script::Builder;
2727
use bitcoin::blockdata::opcodes;
@@ -381,7 +381,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) {
381381
// closing_signed so we do it ourselves
382382
check_closed_broadcast!(nodes[1], false);
383383
check_added_monitors!(nodes[1], 1);
384-
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: SanitizedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
384+
check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) });
385385
}
386386

387387
assert!(nodes[0].node.list_channels().is_empty());

lightning/src/util/events.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
2525
use crate::routing::gossip::NetworkUpdate;
2626
use crate::util::errors::APIError;
2727
use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
28-
use crate::util::string::SanitizedString;
28+
use crate::util::string::UntrustedString;
2929
use crate::routing::router::{RouteHop, RouteParameters};
3030

3131
use bitcoin::{PackedLockTime, Transaction};
@@ -128,10 +128,10 @@ pub enum ClosureReason {
128128
///
129129
/// Be careful about printing the peer_msg, a well-crafted message could exploit
130130
/// a security vulnerability in the terminal emulator or the logging subsystem.
131-
/// To be safe, use `Display` on `SanitizedString`
131+
/// To be safe, use `Display` on `UntrustedString`
132132
///
133-
/// [`SanitizedString`]: crate::util::string::SanitizedString
134-
peer_msg: SanitizedString,
133+
/// [`UntrustedString`]: crate::util::string::UntrustedString
134+
peer_msg: UntrustedString,
135135
},
136136
/// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
137137
///

lightning/src/util/string.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ use crate::util::ser::{Writeable, Writer, Readable};
1717

1818
/// Struct to `Display` fields in a safe way using `PrintableString`
1919
#[derive(Clone, Debug, PartialEq, Eq)]
20-
pub struct SanitizedString(pub String);
20+
pub struct UntrustedString(pub String);
2121

22-
impl Writeable for SanitizedString {
22+
impl Writeable for UntrustedString {
2323
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
2424
self.0.write(w)
2525
}
2626
}
2727

28-
impl Readable for SanitizedString {
28+
impl Readable for UntrustedString {
2929
fn read<R: Read>(r: &mut R) -> Result<Self, msgs::DecodeError> {
3030
let s: String = Readable::read(r)?;
3131
Ok(Self(s))
3232
}
3333
}
3434

35-
impl fmt::Display for SanitizedString {
35+
impl fmt::Display for UntrustedString {
3636
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3737
PrintableString(&self.0).fmt(f)
3838
}

0 commit comments

Comments
 (0)