mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
fuzz: target for update_fail_htlc
Fuzz the decoding and encoding of update_fail_htlc.
This commit is contained in:
parent
fb6d5cf587
commit
298fe06c20
43
tests/fuzz/fuzz-wire-update_fail_htlc.c
Normal file
43
tests/fuzz/fuzz-wire-update_fail_htlc.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include "config.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 update_fail_htlc {
|
||||
struct channel_id channel_id;
|
||||
u64 id;
|
||||
u8 *reason;
|
||||
};
|
||||
|
||||
static void *encode(const tal_t *ctx, const struct update_fail_htlc *s)
|
||||
{
|
||||
return towire_update_fail_htlc(ctx, &s->channel_id, s->id, s->reason);
|
||||
}
|
||||
|
||||
static struct update_fail_htlc *decode(const tal_t *ctx, const void *p)
|
||||
{
|
||||
struct update_fail_htlc *s = tal(ctx, struct update_fail_htlc);
|
||||
|
||||
if (fromwire_update_fail_htlc(s, p, &s->channel_id, &s->id, &s->reason))
|
||||
return s;
|
||||
return tal_free(s);
|
||||
}
|
||||
|
||||
static bool equal(const struct update_fail_htlc *x,
|
||||
const struct update_fail_htlc *y)
|
||||
{
|
||||
size_t upto_reason = (uintptr_t)&x->reason - (uintptr_t)x;
|
||||
if (memcmp(x, y, upto_reason) != 0)
|
||||
return false;
|
||||
|
||||
return memeq(x->reason, tal_bytelen(x->reason), y->reason,
|
||||
tal_bytelen(y->reason));
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
{
|
||||
test_decode_encode(data, size, WIRE_UPDATE_FAIL_HTLC,
|
||||
struct update_fail_htlc);
|
||||
}
|
Loading…
Reference in New Issue
Block a user