mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 15:20:24 +01:00
Rely on Error/Warning message data lengths being correct
In https://github.com/lightning/bolts/pull/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.
This commit is contained in:
parent
2d7b06e619
commit
d786bfaef2
1 changed files with 11 additions and 9 deletions
|
@ -33,7 +33,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
|
||||||
use ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
|
use ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
|
||||||
|
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
use core::{cmp, fmt};
|
use core::fmt;
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
use io::{self, Read};
|
use io::{self, Read};
|
||||||
use io_extras::read_to_end;
|
use io_extras::read_to_end;
|
||||||
|
@ -1529,10 +1529,11 @@ impl Readable for ErrorMessage {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
channel_id: Readable::read(r)?,
|
channel_id: Readable::read(r)?,
|
||||||
data: {
|
data: {
|
||||||
let mut sz: usize = <u16 as Readable>::read(r)? as usize;
|
let sz: usize = <u16 as Readable>::read(r)? as usize;
|
||||||
let data = read_to_end(r)?;
|
let mut data = Vec::with_capacity(sz);
|
||||||
sz = cmp::min(data.len(), sz);
|
data.resize(sz, 0);
|
||||||
match String::from_utf8(data[..sz as usize].to_vec()) {
|
r.read_exact(&mut data)?;
|
||||||
|
match String::from_utf8(data) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return Err(DecodeError::InvalidValue),
|
Err(_) => return Err(DecodeError::InvalidValue),
|
||||||
}
|
}
|
||||||
|
@ -1555,10 +1556,11 @@ impl Readable for WarningMessage {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
channel_id: Readable::read(r)?,
|
channel_id: Readable::read(r)?,
|
||||||
data: {
|
data: {
|
||||||
let mut sz: usize = <u16 as Readable>::read(r)? as usize;
|
let sz: usize = <u16 as Readable>::read(r)? as usize;
|
||||||
let data = read_to_end(r)?;
|
let mut data = Vec::with_capacity(sz);
|
||||||
sz = cmp::min(data.len(), sz);
|
data.resize(sz, 0);
|
||||||
match String::from_utf8(data[..sz as usize].to_vec()) {
|
r.read_exact(&mut data)?;
|
||||||
|
match String::from_utf8(data) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return Err(DecodeError::InvalidValue),
|
Err(_) => return Err(DecodeError::InvalidValue),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue