Skip to content

Commit b679944

Browse files
committed
f: don't assert in production code
1 parent 7ecd863 commit b679944

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lightning/src/ln/onion_utils.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,22 @@ pub(super) fn construct_trampoline_onion_packet(
431431
) -> Result<msgs::TrampolineOnionPacket, ()> {
432432
let minimum_packet_length = payloads.iter().map(|p| p.serialized_length() + 32).sum();
433433

434-
assert!(
434+
debug_assert!(
435435
minimum_packet_length < ONION_DATA_LEN,
436436
"Trampoline onion packet must be smaller than outer onion"
437437
);
438+
if minimum_packet_length >= ONION_DATA_LEN {
439+
return Err(());
440+
}
438441

439442
let packet_length = usize::from(length.unwrap_or(minimum_packet_length as u16));
440-
assert!(
443+
debug_assert!(
441444
packet_length >= minimum_packet_length,
442445
"Packet length cannot be smaller than the payloads require."
443446
);
447+
if packet_length < minimum_packet_length {
448+
return Err(());
449+
}
444450

445451
let mut packet_data = vec![0u8; packet_length];
446452
let mut chacha = ChaCha20::new(&prng_seed, &[0; 8]);

0 commit comments

Comments
 (0)