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