forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fuzz the decoding and encoding of tx_add_output.
- Loading branch information
1 parent
dac211c
commit c0e8cce
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#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 tx_add_output { | ||
struct channel_id channel_id; | ||
u64 serial_id; | ||
u64 sats; | ||
u8 *script; | ||
}; | ||
|
||
static void *encode(const tal_t *ctx, const struct tx_add_output *s) | ||
{ | ||
return towire_tx_add_output(ctx, &s->channel_id, s->serial_id, s->sats, | ||
s->script); | ||
} | ||
|
||
static struct tx_add_output *decode(const tal_t *ctx, const void *p) | ||
{ | ||
struct tx_add_output *s = tal(ctx, struct tx_add_output); | ||
|
||
if (fromwire_tx_add_output(s, p, &s->channel_id, &s->serial_id, | ||
&s->sats, &s->script)) | ||
return s; | ||
return tal_free(s); | ||
} | ||
|
||
static bool equal(const struct tx_add_output *x, const struct tx_add_output *y) | ||
{ | ||
size_t upto_script = (uintptr_t)&x->script - (uintptr_t)x; | ||
if (memcmp(x, y, upto_script) != 0) | ||
return false; | ||
|
||
return memeq(x->script, tal_bytelen(x->script), y->script, | ||
tal_bytelen(y->script)); | ||
} | ||
|
||
void run(const u8 *data, size_t size) | ||
{ | ||
test_decode_encode(data, size, WIRE_TX_ADD_OUTPUT, | ||
struct tx_add_output); | ||
} |