fuzz-tests: Add a wire test for wireaddr functions
What changed, and why it matters
This commit adds a new automated fuzz test file for network address parsing and serialization functions. It does not change any production code, fix a bug, or alter behavior. It is purely a test addition intended to improve code coverage and catch future bugs.
No security action needed. Review as a normal test addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces tests/fuzz/fuzz-wireaddr.c, a libFuzzer harness that converts arbitrary fuzz input to a string, calls parse_wireaddr(), and if parsing succeeds, round-trips the resulting struct wireaddr through towire_wireaddr() and fromwire_wireaddr(), asserting equality. No production code is modified.
Changed components
tests/fuzz/fuzz-wireaddr.cInspect captured patch +42 / −0
diff --git a/tests/fuzz/fuzz-wireaddr.c b/tests/fuzz/fuzz-wireaddr.c
new file mode 100644
index 00000000..32d480ba
--- /dev/null
+++ b/tests/fuzz/fuzz-wireaddr.c
@@ -0,0 +1,42 @@
+#include "config.h"
+#include <assert.h>
+#include <bitcoin/chainparams.h>
+#include <ccan/ccan/tal/str/str.h>
+#include <common/setup.h>
+#include <common/utils.h>
+#include <common/wireaddr.h>
+#include <tests/fuzz/libfuzz.h>
+
+#define DEFAULT_PORT 9735
+
+void init(int *argc, char ***argv)
+{
+ /* Don't call this if we're in unit-test mode, as libfuzz.c does it */
+ if (!tmpctx)
+ common_setup("fuzzer");
+ chainparams = chainparams_for_network("bitcoin");
+}
+
+void run(const uint8_t *data, size_t size)
+{
+ char *addr = to_string(tmpctx, data, size);
+
+ struct wireaddr wa, decoded_wa;
+ const char *err;
+
+ err = parse_wireaddr(tmpctx, addr, DEFAULT_PORT, NULL, &wa);
+
+ if (!err) {
+ assert(fmt_wireaddr(tmpctx, &wa));
+
+ u8 *output_buffer = tal_arr(tmpctx, u8, 0);
+ towire_wireaddr(&output_buffer, &wa);
+ size_t len = tal_bytelen(output_buffer);
+
+ assert(fromwire_wireaddr((const u8 **)&output_buffer, &len,
+ &decoded_wa));
+ assert(wireaddr_eq(&wa, &decoded_wa));
+ }
+
+ clean_tmpctx();
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.