Skip to content

Commit

Permalink
Rely on Error/Warning message data lengths being correct
Browse files Browse the repository at this point in the history
In lightning/bolts#950, the (somewhat
strange) requirement that error messages be handled even if the
length field is set larger than the size of the package was
removed. Here we change the code to drop the special handling for
this, opting to just fail to read the message if the length is
incorrect.
  • Loading branch information
TheBlueMatt committed Jan 10, 2022
1 parent bb79e05 commit dc3e097
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,10 +1524,11 @@ impl Readable for ErrorMessage {
Ok(Self {
channel_id: Readable::read(r)?,
data: {
let mut sz: usize = <u16 as Readable>::read(r)? as usize;
let data = read_to_end(r)?;
sz = cmp::min(data.len(), sz);
match String::from_utf8(data[..sz as usize].to_vec()) {
let sz: usize = <u16 as Readable>::read(r)? as usize;
let mut data = Vec::with_capacity(sz);
data.resize(sz, 0);
r.read_exact(&mut data)?;
match String::from_utf8(data) {
Ok(s) => s,
Err(_) => return Err(DecodeError::InvalidValue),
}
Expand All @@ -1550,10 +1551,11 @@ impl Readable for WarningMessage {
Ok(Self {
channel_id: Readable::read(r)?,
data: {
let mut sz: usize = <u16 as Readable>::read(r)? as usize;
let data = read_to_end(r)?;
sz = cmp::min(data.len(), sz);
match String::from_utf8(data[..sz as usize].to_vec()) {
let sz: usize = <u16 as Readable>::read(r)? as usize;
let mut data = Vec::with_capacity(sz);
data.resize(sz, 0);
r.read_exact(&mut data)?;
match String::from_utf8(data) {
Ok(s) => s,
Err(_) => return Err(DecodeError::InvalidValue),
}
Expand Down

0 comments on commit dc3e097

Please sign in to comment.