Skip to content

Commit c45d8eb

Browse files
committed
Only abort channel_target fuzz test on Err if ErrorAction says to
1 parent 0ce6e39 commit c45d8eb

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

fuzz/fuzz_targets/channel_target.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bitcoin::network::serialize::{serialize, BitcoinHash};
1010
use lightning::ln::channel::{Channel, ChannelKeys};
1111
use lightning::ln::channelmanager::{HTLCFailReason, PendingForwardHTLCInfo};
1212
use lightning::ln::msgs;
13-
use lightning::ln::msgs::MsgDecodable;
13+
use lightning::ln::msgs::{MsgDecodable, ErrorAction};
1414
use lightning::chain::chaininterface::{FeeEstimator, ConfirmationTarget};
1515
use lightning::chain::transaction::OutPoint;
1616
use lightning::util::reset_rng_state;
@@ -239,55 +239,71 @@ pub fn do_test(data: &[u8]) {
239239
let funding_locked = decode_msg!(msgs::FundingLocked, 32+33);
240240
return_err!(channel.funding_locked(&funding_locked));
241241

242+
macro_rules! test_err {
243+
($expr: expr) => {
244+
match $expr {
245+
Ok(r) => Some(r),
246+
Err(e) => match e.action {
247+
None => return,
248+
Some(ErrorAction::UpdateFailHTLC {..}) => None,
249+
Some(ErrorAction::DisconnectPeer {..}) => return,
250+
Some(ErrorAction::IgnoreError) => None,
251+
Some(ErrorAction::SendErrorMessage {..}) => None,
252+
},
253+
}
254+
}
255+
}
256+
242257
loop {
243258
match get_slice!(1)[0] {
244259
0 => {
245-
return_err!(channel.send_htlc(slice_to_be64(get_slice!(8)), [42; 32], slice_to_be32(get_slice!(4)), msgs::OnionPacket {
260+
test_err!(channel.send_htlc(slice_to_be64(get_slice!(8)), [42; 32], slice_to_be32(get_slice!(4)), msgs::OnionPacket {
246261
version: get_slice!(1)[0],
247262
public_key: get_pubkey!(),
248263
hop_data: [0; 20*65],
249264
hmac: [0; 32],
250265
}));
251266
},
252267
1 => {
253-
return_err!(channel.send_commitment());
268+
test_err!(channel.send_commitment());
254269
},
255270
2 => {
256271
let update_add_htlc = decode_msg!(msgs::UpdateAddHTLC, 32+8+8+32+4+4+33+20*65+32);
257-
return_err!(channel.update_add_htlc(&update_add_htlc, PendingForwardHTLCInfo::dummy()));
272+
test_err!(channel.update_add_htlc(&update_add_htlc, PendingForwardHTLCInfo::dummy()));
258273
},
259274
3 => {
260275
let update_fulfill_htlc = decode_msg!(msgs::UpdateFulfillHTLC, 32 + 8 + 32);
261-
return_err!(channel.update_fulfill_htlc(&update_fulfill_htlc));
276+
test_err!(channel.update_fulfill_htlc(&update_fulfill_htlc));
262277
},
263278
4 => {
264279
let update_fail_htlc = decode_msg_with_len16!(msgs::UpdateFailHTLC, 32 + 8, 1);
265-
return_err!(channel.update_fail_htlc(&update_fail_htlc, HTLCFailReason::dummy()));
280+
test_err!(channel.update_fail_htlc(&update_fail_htlc, HTLCFailReason::dummy()));
266281
},
267282
5 => {
268283
let update_fail_malformed_htlc = decode_msg!(msgs::UpdateFailMalformedHTLC, 32+8+32+2);
269-
return_err!(channel.update_fail_malformed_htlc(&update_fail_malformed_htlc, HTLCFailReason::dummy()));
284+
test_err!(channel.update_fail_malformed_htlc(&update_fail_malformed_htlc, HTLCFailReason::dummy()));
270285
},
271286
6 => {
272287
let commitment_signed = decode_msg_with_len16!(msgs::CommitmentSigned, 32+64, 64);
273-
return_err!(channel.commitment_signed(&commitment_signed));
288+
test_err!(channel.commitment_signed(&commitment_signed));
274289
},
275290
7 => {
276291
let revoke_and_ack = decode_msg!(msgs::RevokeAndACK, 32+32+33);
277-
return_err!(channel.revoke_and_ack(&revoke_and_ack));
292+
test_err!(channel.revoke_and_ack(&revoke_and_ack));
278293
},
279294
8 => {
280295
let update_fee = decode_msg!(msgs::UpdateFee, 32+4);
281-
return_err!(channel.update_fee(&fee_est, &update_fee));
296+
test_err!(channel.update_fee(&fee_est, &update_fee));
282297
},
283298
9 => {
284299
let shutdown = decode_msg_with_len16!(msgs::Shutdown, 32, 1);
285-
return_err!(channel.shutdown(&fee_est, &shutdown));
300+
test_err!(channel.shutdown(&fee_est, &shutdown));
286301
if channel.is_shutdown() { return; }
287302
},
288303
10 => {
289304
let closing_signed = decode_msg!(msgs::ClosingSigned, 32+8+64);
290-
if return_err!(channel.closing_signed(&fee_est, &closing_signed)).1.is_some() {
305+
let sign_res = test_err!(channel.closing_signed(&fee_est, &closing_signed));
306+
if sign_res.is_some() && sign_res.unwrap().1.is_some() {
291307
assert!(channel.is_shutdown());
292308
return;
293309
}

0 commit comments

Comments
 (0)