From 396d0a9c2e2fb49ecc7599e4996a5a5a39e45890 Mon Sep 17 00:00:00 2001 From: Chandra Pratap Date: Tue, 20 May 2025 07:00:19 +0000 Subject: [PATCH 1/2] fuzz-tests: order FUZZ_COMMON_OBJS lexicographic The FUZZ_COMMON_OBJS list roughly follows lexicographic order. Make it adhere strictly to the order. This makes adding and reviewing changes to the file easier. --- tests/fuzz/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile index e60c26e7b13c..720302b9d5ab 100644 --- a/tests/fuzz/Makefile +++ b/tests/fuzz/Makefile @@ -13,24 +13,24 @@ FUZZ_TARGETS_OBJS := $(FUZZ_TARGETS_SRC:.c=.o) FUZZ_TARGETS_BIN := $(FUZZ_TARGETS_SRC:.c=) FUZZ_COMMON_OBJS := \ - common/amount.o \ common/addr.o \ + common/amount.o \ common/autodata.o \ common/base32.o \ common/base64.o \ common/bech32.o \ common/bech32_util.o \ - common/bip32.o \ common/bigsize.o \ + common/bip32.o \ common/blockheight_states.o \ common/bolt11.o \ common/bolt12_merkle.o \ common/channel_config.o \ + common/channel_id.o \ + common/channel_type.o \ common/close_tx.o \ common/configdir.o \ common/configvar.o \ - common/channel_id.o \ - common/channel_type.o \ common/cryptomsg.o \ common/daemon.o \ common/daemon_conn.o \ @@ -41,16 +41,15 @@ FUZZ_COMMON_OBJS := \ common/hash_u5.o \ common/hsm_encryption.o \ common/htlc_state.o \ - common/permute_tx.o \ common/initial_channel.o \ common/initial_commit_tx.o \ common/key_derive.o \ common/keyset.o \ - common/msg_queue.o \ common/memleak.o \ + common/msg_queue.o \ common/node_id.o \ + common/permute_tx.o \ common/psbt_keypath.o \ - common/wireaddr.o \ common/sciddir_or_pubkey.o \ common/setup.o \ common/status.o \ @@ -58,12 +57,13 @@ FUZZ_COMMON_OBJS := \ common/status_wiregen.o \ common/utils.o \ common/version.o \ + common/wireaddr.o \ wire/bolt12_wiregen.o \ + wire/channel_type_wiregen.o \ wire/fromwire.o \ wire/onion_wiregen.o \ wire/peer_wire.o \ wire/peer_wiregen.o \ - wire/channel_type_wiregen.o \ wire/tlvstream.o \ wire/towire.o \ wire/wire_io.o \ From 5af4f63e246702e5511855b47c39056cbd04882d Mon Sep 17 00:00:00 2001 From: Chandra Pratap Date: Tue, 20 May 2025 07:19:44 +0000 Subject: [PATCH 2/2] fuzz-tests: add a test for handle_peer_error_or_warning() handle_peer_error_or_warning() in common/read_peer_message is responsible for parsing any incoming `error` or `warning` messages as defined in BOLT #1. Add a test for it. --- tests/fuzz/Makefile | 6 ++++++ tests/fuzz/fuzz-error-warning.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/fuzz/fuzz-error-warning.c diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile index 720302b9d5ab..bcd1d73c67a9 100644 --- a/tests/fuzz/Makefile +++ b/tests/fuzz/Makefile @@ -48,8 +48,13 @@ FUZZ_COMMON_OBJS := \ common/memleak.o \ common/msg_queue.o \ common/node_id.o \ + common/peer_billboard.o \ + common/peer_failed.o \ + common/peer_io.o \ + common/peer_status_wiregen.o \ common/permute_tx.o \ common/psbt_keypath.o \ + common/read_peer_msg.o \ common/sciddir_or_pubkey.o \ common/setup.o \ common/status.o \ @@ -58,6 +63,7 @@ FUZZ_COMMON_OBJS := \ common/utils.o \ common/version.o \ common/wireaddr.o \ + common/wire_error.o \ wire/bolt12_wiregen.o \ wire/channel_type_wiregen.o \ wire/fromwire.o \ diff --git a/tests/fuzz/fuzz-error-warning.c b/tests/fuzz/fuzz-error-warning.c new file mode 100644 index 000000000000..8b70c34803fa --- /dev/null +++ b/tests/fuzz/fuzz-error-warning.c @@ -0,0 +1,17 @@ +#include "config.h" +#include +#include +#include + +void init(int *argc, char ***argv) +{ +} + +void run(const u8 *data, size_t size) +{ + struct per_peer_state pps = { .peer_fd = -1 }; + u8 *buf = tal_dup_arr(NULL, u8, data, size, 0); + handle_peer_error_or_warning(&pps, buf); + + tal_free(buf); +} \ No newline at end of file