Skip to content

Commit

Permalink
Fix possible incomplete read bug on onion packet decode
Browse files Browse the repository at this point in the history
Pre-existing to this PR, we were reading next packet bytes with io::Read::read,
which is not guaranteed to read all the bytes we need, only guaranteed to read
*some* bytes.

We fix this to be read_exact, which is guaranteed to read all the next hop
packet bytes.
  • Loading branch information
valentinewallace committed Aug 2, 2022
1 parent 3bdf795 commit 4919172
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lightning/src/ln/onion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ pub(crate) fn decode_next_hop<D: DecodeInput, R: ReadableArgs<D::Arg>, N: NextPa
return Ok((msg, None)); // We are the final destination for this packet
} else {
let mut new_packet_bytes = N::new(hop_data.len());
let read_pos = chacha_stream.read(new_packet_bytes.as_mut()).unwrap();
let read_pos = hop_data.len() - chacha_stream.read.position() as usize;
chacha_stream.read_exact(&mut new_packet_bytes.as_mut()[..read_pos]).unwrap();
#[cfg(debug_assertions)]
{
// Check two things:
Expand Down

0 comments on commit 4919172

Please sign in to comment.