|
| 1 | +#include "config.h" |
| 2 | +#include <stdio.h> |
| 3 | +#include <fcntl.h> |
| 4 | +#include <setjmp.h> |
| 5 | +#include <common/per_peer_state.h> |
| 6 | +#include <common/peer_failed.h> |
| 7 | +#include <common/read_peer_msg.h> |
| 8 | +#include <common/status.h> |
| 9 | +#include <common/utils.h> |
| 10 | +#include <tests/fuzz/libfuzz.h> |
| 11 | + |
| 12 | +static jmp_buf exit_jmp; |
| 13 | + |
| 14 | +/* MOCKS START */ |
| 15 | +/* Stub for peer_failed_connection_lost */ |
| 16 | +void peer_failed_connection_lost(void) |
| 17 | +{ fprintf(stderr, "peer_failed_connection_lost called!\n"); abort(); } |
| 18 | +/* Stub for peer_failed_received_errmsg */ |
| 19 | +void peer_failed_received_errmsg(struct per_peer_state *pps UNNEEDED, |
| 20 | + bool disconnect UNNEEDED, |
| 21 | + const char *desc) |
| 22 | + |
| 23 | +{ longjmp(exit_jmp, 1); } |
| 24 | +/* MOCKS END */ |
| 25 | + |
| 26 | +void init(int *argc, char ***argv) |
| 27 | +{ |
| 28 | + int devnull = open("/dev/null", O_WRONLY); |
| 29 | + status_setup_sync(devnull); |
| 30 | +} |
| 31 | + |
| 32 | +void run(const u8 *data, size_t size) |
| 33 | +{ |
| 34 | + if (setjmp(exit_jmp) != 0) |
| 35 | + return; |
| 36 | + |
| 37 | + u8 *msg = tal_dup_arr(tmpctx, u8, data, size, 0); |
| 38 | + struct per_peer_state pps = { .peer_fd = -1 }; |
| 39 | + handle_peer_error_or_warning(&pps, msg); |
| 40 | + |
| 41 | + clean_tmpctx(); |
| 42 | +} |
0 commit comments