Skip to content

fuzz-tests: add a test for handle_peer_error_or_warning() #8304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions tests/fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -41,29 +41,29 @@ 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 \
common/status_wire.o \
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 \
Expand All @@ -72,5 +72,11 @@ FUZZ_COMMON_OBJS := \
$(FUZZ_TARGETS_OBJS): $(COMMON_HEADERS) $(WIRE_HEADERS) $(COMMON_SRC)
$(FUZZ_TARGETS_BIN): $(LIBFUZZ_OBJS) $(FUZZ_COMMON_OBJS) $(BITCOIN_OBJS)

tests/fuzz/fuzz-error-warning: common/peer_billboard.o \
common/wire_error.o \
common/peer_io.o \
common/read_peer_msg.o \
common/peer_status_wiregen.o

ALL_C_SOURCES += $(FUZZ_TARGETS_SRC) $(LIBFUZZ_SRC)
ALL_FUZZ_TARGETS += $(FUZZ_TARGETS_BIN)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
&
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
?
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
&
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/fuzz/fuzz-error-warning.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "config.h"
#include <stdio.h>
#include <fcntl.h>
#include <setjmp.h>
#include <common/per_peer_state.h>
#include <common/peer_failed.h>
#include <common/read_peer_msg.h>
#include <common/status.h>
#include <common/utils.h>
#include <tests/fuzz/libfuzz.h>

static jmp_buf exit_jmp;

/* MOCKS START */
/* Stub for peer_failed_connection_lost */
void peer_failed_connection_lost(void)
{ fprintf(stderr, "peer_failed_connection_lost called!\n"); abort(); }
/* Stub for peer_failed_received_errmsg */
void peer_failed_received_errmsg(struct per_peer_state *pps UNNEEDED,
bool disconnect UNNEEDED,
const char *desc)

{ longjmp(exit_jmp, 1); }
/* MOCKS END */

void init(int *argc, char ***argv)
{
int devnull = open("/dev/null", O_WRONLY);
status_setup_sync(devnull);
}

void run(const u8 *data, size_t size)
{
if (setjmp(exit_jmp) != 0)
return;

u8 *msg = tal_dup_arr(tmpctx, u8, data, size, 0);
struct per_peer_state pps = { .peer_fd = -1 };
handle_peer_error_or_warning(&pps, msg);

clean_tmpctx();
}