From 38a329f9e629c2b2a90e6e76fbc9d2e0ef3e49c3 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Mon, 21 Aug 2023 15:38:32 -0500 Subject: [PATCH] fuzz: target for closing_signed Fuzz the decoding and encoding of closing_signed. --- tests/fuzz/fuzz-wire-closing_signed.c | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/fuzz/fuzz-wire-closing_signed.c diff --git a/tests/fuzz/fuzz-wire-closing_signed.c b/tests/fuzz/fuzz-wire-closing_signed.c new file mode 100644 index 000000000..a8ae34f7d --- /dev/null +++ b/tests/fuzz/fuzz-wire-closing_signed.c @@ -0,0 +1,48 @@ +#include "config.h" +#include +#include +#include +#include +#include +#include + +struct closing_signed { + struct channel_id channel_id; + struct amount_sat fee_satoshis; + secp256k1_ecdsa_signature signature; + struct tlv_closing_signed_tlvs *tlvs; +}; + +static void *encode(const tal_t *ctx, const struct closing_signed *s) +{ + return towire_closing_signed(ctx, &s->channel_id, s->fee_satoshis, + &s->signature, s->tlvs); +} + +static struct closing_signed *decode(const tal_t *ctx, const void *p) +{ + struct closing_signed *s = tal(ctx, struct closing_signed); + + if (fromwire_closing_signed(s, p, &s->channel_id, &s->fee_satoshis, + &s->signature, &s->tlvs)) + return s; + return tal_free(s); +} + +static bool equal(const struct closing_signed *x, + const struct closing_signed *y) +{ + size_t upto_tlvs = (uintptr_t)&x->tlvs - (uintptr_t)x; + if (memcmp(x, y, upto_tlvs) != 0) + return false; + + assert(x->tlvs && y->tlvs); + return memeq(x->tlvs->fee_range, tal_bytelen(x->tlvs->fee_range), + y->tlvs->fee_range, tal_bytelen(y->tlvs->fee_range)); +} + +void run(const u8 *data, size_t size) +{ + test_decode_encode(data, size, WIRE_CLOSING_SIGNED, + struct closing_signed); +}