mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
fuzz: target for channel_reestablish
Fuzz the decoding and encoding of channel_reestablish.
This commit is contained in:
parent
7686909c65
commit
b7b046ce83
1 changed files with 73 additions and 0 deletions
73
tests/fuzz/fuzz-wire-channel_reestablish.c
Normal file
73
tests/fuzz/fuzz-wire-channel_reestablish.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <stdint.h>
|
||||
#include <tests/fuzz/libfuzz.h>
|
||||
#include <tests/fuzz/wire.h>
|
||||
#include <wire/peer_wire.h>
|
||||
|
||||
struct channel_reestablish {
|
||||
struct channel_id channel_id;
|
||||
u64 next_commitment_number;
|
||||
u64 next_revocation_number;
|
||||
struct secret your_last_per_commitment_secret;
|
||||
struct pubkey my_current_per_commitment_point;
|
||||
struct tlv_channel_reestablish_tlvs *tlvs;
|
||||
};
|
||||
|
||||
static void *encode(const tal_t *ctx, const struct channel_reestablish *s)
|
||||
{
|
||||
return towire_channel_reestablish(
|
||||
ctx, &s->channel_id, s->next_commitment_number,
|
||||
s->next_revocation_number, &s->your_last_per_commitment_secret,
|
||||
&s->my_current_per_commitment_point, s->tlvs);
|
||||
}
|
||||
|
||||
static struct channel_reestablish *decode(const tal_t *ctx, const void *p)
|
||||
{
|
||||
struct channel_reestablish *s = tal(ctx, struct channel_reestablish);
|
||||
|
||||
if (fromwire_channel_reestablish(
|
||||
s, p, &s->channel_id, &s->next_commitment_number,
|
||||
&s->next_revocation_number, &s->your_last_per_commitment_secret,
|
||||
&s->my_current_per_commitment_point, &s->tlvs))
|
||||
return s;
|
||||
return tal_free(s);
|
||||
}
|
||||
|
||||
static bool equal(const struct channel_reestablish *x,
|
||||
const struct channel_reestablish *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);
|
||||
|
||||
if (!memeq(x->tlvs->next_funding, tal_bytelen(x->tlvs->next_funding),
|
||||
y->tlvs->next_funding, tal_bytelen(y->tlvs->next_funding)))
|
||||
return false;
|
||||
if (!memeq(x->tlvs->next_to_send, tal_bytelen(x->tlvs->next_to_send),
|
||||
y->tlvs->next_to_send, tal_bytelen(y->tlvs->next_to_send)))
|
||||
return false;
|
||||
if (!memeq(x->tlvs->desired_channel_type,
|
||||
tal_bytelen(x->tlvs->desired_channel_type),
|
||||
y->tlvs->desired_channel_type,
|
||||
tal_bytelen(y->tlvs->desired_channel_type)))
|
||||
return false;
|
||||
if (!memeq(x->tlvs->current_channel_type,
|
||||
tal_bytelen(x->tlvs->current_channel_type),
|
||||
y->tlvs->current_channel_type,
|
||||
tal_bytelen(y->tlvs->current_channel_type)))
|
||||
return false;
|
||||
return memeq(x->tlvs->upgradable_channel_type,
|
||||
tal_bytelen(x->tlvs->upgradable_channel_type),
|
||||
y->tlvs->upgradable_channel_type,
|
||||
tal_bytelen(y->tlvs->upgradable_channel_type));
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
{
|
||||
test_decode_encode(data, size, WIRE_CHANNEL_REESTABLISH,
|
||||
struct channel_reestablish);
|
||||
}
|
Loading…
Add table
Reference in a new issue