mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
fuzz: target for init
Fuzz the decoding and encoding of init.
This commit is contained in:
parent
e41f263b72
commit
b437835241
1 changed files with 50 additions and 0 deletions
50
tests/fuzz/fuzz-wire-init.c
Normal file
50
tests/fuzz/fuzz-wire-init.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <tests/fuzz/libfuzz.h>
|
||||
#include <tests/fuzz/wire.h>
|
||||
#include <wire/peer_wire.h>
|
||||
|
||||
struct init {
|
||||
u8 *globalfeatures;
|
||||
u8 *features;
|
||||
struct tlv_init_tlvs *tlvs;
|
||||
};
|
||||
|
||||
static void *encode(const tal_t *ctx, const struct init *s)
|
||||
{
|
||||
return towire_init(ctx, s->globalfeatures, s->features, s->tlvs);
|
||||
}
|
||||
|
||||
static struct init *decode(const tal_t *ctx, const void *p)
|
||||
{
|
||||
struct init *s = tal(ctx, struct init);
|
||||
|
||||
if (fromwire_init(s, p, &s->globalfeatures, &s->features, &s->tlvs))
|
||||
return s;
|
||||
return tal_free(s);
|
||||
}
|
||||
|
||||
static bool equal(const struct init *x, const struct init *y)
|
||||
{
|
||||
if (!memeq(x->globalfeatures, tal_bytelen(x->globalfeatures),
|
||||
y->globalfeatures, tal_bytelen(y->globalfeatures)))
|
||||
return false;
|
||||
if (!memeq(x->features, tal_bytelen(x->features), y->features,
|
||||
tal_bytelen(y->features)))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->networks, tal_bytelen(x->tlvs->networks),
|
||||
y->tlvs->networks, tal_bytelen(y->tlvs->networks)))
|
||||
return false;
|
||||
|
||||
return memeq(x->tlvs->remote_addr, tal_bytelen(x->tlvs->remote_addr),
|
||||
y->tlvs->remote_addr, tal_bytelen(y->tlvs->remote_addr));
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
{
|
||||
test_decode_encode(data, size, WIRE_INIT, struct init);
|
||||
}
|
Loading…
Add table
Reference in a new issue