diff --git a/common/node_id.c b/common/node_id.c index 4998323e2..f98bb8159 100644 --- a/common/node_id.c +++ b/common/node_id.c @@ -56,14 +56,16 @@ void fromwire_node_id(const u8 **cursor, size_t *max, struct node_id *id) fromwire(cursor, max, &id->k, sizeof(id->k)); } +bool dev_towire_allow_invalid_node_id = false; + void towire_node_id(u8 **pptr, const struct node_id *id) { -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION /* Cheap sanity check. For wire fuzzing, we only care about correct * encoding of node IDs and not whether the IDs are valid, so we disable * this check while fuzzing. */ - assert(id->k[0] == 0x2 || id->k[0] == 0x3); -#endif + if (!dev_towire_allow_invalid_node_id) + assert(id->k[0] == 0x2 || id->k[0] == 0x3); + towire(pptr, id->k, sizeof(id->k)); } diff --git a/common/node_id.h b/common/node_id.h index 0f943a44a..6b1087ed1 100644 --- a/common/node_id.h +++ b/common/node_id.h @@ -48,6 +48,9 @@ static inline int node_id_idx(const struct node_id *id1, void towire_node_id(u8 **pptr, const struct node_id *id); void fromwire_node_id(const u8 **cursor, size_t *max, struct node_id *id); +/* Fuzzer creates these, so sets this flag to allow it */ +extern bool dev_towire_allow_invalid_node_id; + /* Hash table functions for node ids */ static inline const struct node_id *node_id_keyof(const struct node_id *id) { diff --git a/tests/fuzz/wire.h b/tests/fuzz/wire.h index 28a523064..23d1ee1c1 100644 --- a/tests/fuzz/wire.h +++ b/tests/fuzz/wire.h @@ -21,7 +21,7 @@ static u8 *prefix_arr(const u8 *data, size_t size, u16 prefix) } /* The init function used by all fuzz-wire-* targets. */ -void init(int *argc, char ***argv) { common_setup("fuzzer"); } +void init(int *argc, char ***argv) { common_setup("fuzzer"); dev_towire_allow_invalid_node_id = true; } /* Test that decoding arbitrary data does not crash. Then, if the data was * successfully decoded, test that encoding and decoding the message does not