Skip to content

Commit

Permalink
avoid panix in the slice
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Jun 27, 2022
1 parent 9706938 commit 2fc7023
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions zebra-network/src/protocol/external/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,11 @@ where
E: Error,
{
fn from(e: E) -> Self {
let message_bytes = e.to_string().zcash_serialize_to_vec().unwrap_or_default();

Message::Reject {
message: String::from_utf8(
e.to_string().zcash_serialize_to_vec().unwrap_or_default()
[0..MAX_REJECT_MESSAGE_LENGTH]
message_bytes[0..std::cmp::min(MAX_REJECT_MESSAGE_LENGTH, message_bytes.len())]
.to_vec(),
)
.unwrap_or_else(|_| String::from("")),
Expand All @@ -369,11 +370,13 @@ where
ccode: RejectReason::Other,

reason: if let Some(reason) = e.source() {
let reason_bytes = reason
.to_string()
.zcash_serialize_to_vec()
.unwrap_or_default();

String::from_utf8(
reason
.to_string()
.zcash_serialize_to_vec()
.unwrap_or_default()[0..MAX_REJECT_REASON_LENGTH]
reason_bytes[0..std::cmp::min(MAX_REJECT_REASON_LENGTH, reason_bytes.len())]
.to_vec(),
)
.unwrap_or_else(|_| String::from(""))
Expand Down

0 comments on commit 2fc7023

Please sign in to comment.