Skip to content

Commit cd28570

Browse files
committed
fix fuzz test
1 parent 953e93d commit cd28570

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,18 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
537537
}
538538
}
539539

540-
let mut messages = conduit.decrypt_message_stream(Some(&peer.pending_read_buffer));
541-
542-
if messages.len() != 1 {
543-
break; // the length should initially be one, though there will be a possibility of decrypting multiple messages at once in the future
540+
let mut next_message_result = conduit.decrypt(&peer.pending_read_buffer);
541+
542+
let offset = next_message_result.1;
543+
if offset == 0 {
544+
// nothing got read
545+
break;
546+
}else{
547+
peer.pending_read_buffer.drain(0..offset);
544548
}
545549

546-
let msg_data = messages.remove(1);
550+
// something got read, so we definitely have a message
551+
let msg_data = next_message_result.0.unwrap();
547552

548553
let mut reader = ::std::io::Cursor::new(&msg_data[..]);
549554
let message_result = wire::read(&mut reader);

lightning/src/ln/peers/conduit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Conduit {
7575
}
7676

7777
/// Decrypt a single message. Buffer is an undelimited amount of bytes
78-
fn decrypt(&mut self, buffer: &[u8]) -> (Option<Vec<u8>>, usize) { // the response slice should have the same lifetime as the argument. It's the slice data is read from
78+
pub(crate) fn decrypt(&mut self, buffer: &[u8]) -> (Option<Vec<u8>>, usize) { // the response slice should have the same lifetime as the argument. It's the slice data is read from
7979
if buffer.len() < 18 {
8080
return (None, 0);
8181
}

0 commit comments

Comments
 (0)