X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fmsgs.rs;h=6c7c8cfc7281682af919360df1c892342277e820;hb=4ca5bcf8cfc5cb3868974028b23ab7829c21426b;hp=4500ee2f89f48bee0290257c3c49411169cc0c07;hpb=a3247abb4e9a13bf6b4817c7ce7a571d1d3e0063;p=rust-lightning diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index 4500ee2f..6c7c8cfc 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -5,7 +5,7 @@ use bitcoin::network::serialize::{deserialize,serialize}; use bitcoin::blockdata::script::Script; use std::error::Error; -use std::fmt; +use std::{cmp, fmt}; use std::result::Result; use util::{byte_utils, internal_traits, events}; @@ -399,6 +399,7 @@ pub struct CommitmentUpdate { pub update_add_htlcs: Vec, pub update_fulfill_htlcs: Vec, pub update_fail_htlcs: Vec, + pub update_fail_malformed_htlcs: Vec, pub commitment_signed: CommitmentSigned, } @@ -1626,11 +1627,9 @@ impl MsgDecodable for ErrorMessage { if v.len() < 34 { return Err(DecodeError::ShortRead); } - let len = byte_utils::slice_to_be16(&v[32..34]); - if v.len() < 34 + len as usize { - return Err(DecodeError::ShortRead); - } - let data = match String::from_utf8(v[34..34 + len as usize].to_vec()) { + // Unlike most messages, BOLT 1 requires we truncate our read if the value is out of range + let len = cmp::min(byte_utils::slice_to_be16(&v[32..34]) as usize, v.len() - 34); + let data = match String::from_utf8(v[34..34 + len].to_vec()) { Ok(s) => s, Err(_) => return Err(DecodeError::BadText), };