From d60229ede54e05724d444eaba02a9ed72f5ada02 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 16 May 2023 19:55:10 +0200 Subject: [PATCH 1/3] fuzz: make the parsed descriptor testing into a function We'll be reusing it in the new target. --- src/test/fuzz/descriptor_parse.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/test/fuzz/descriptor_parse.cpp b/src/test/fuzz/descriptor_parse.cpp index 579942c3b51..0e4ef1522f6 100644 --- a/src/test/fuzz/descriptor_parse.cpp +++ b/src/test/fuzz/descriptor_parse.cpp @@ -8,6 +8,14 @@ #include #include +/** Test a successfully parsed descriptor. */ +static void TestDescriptor(const Descriptor& desc) +{ + (void)desc.ToString(); + (void)desc.IsRange(); + (void)desc.IsSolvable(); +} + void initialize_descriptor_parse() { ECC_Start(); @@ -21,10 +29,6 @@ FUZZ_TARGET(descriptor_parse, .init = initialize_descriptor_parse) std::string error; for (const bool require_checksum : {true, false}) { const auto desc = Parse(descriptor, signing_provider, error, require_checksum); - if (desc) { - (void)desc->ToString(); - (void)desc->IsRange(); - (void)desc->IsSolvable(); - } + if (desc) TestDescriptor(*desc); } } From 90a24741e79cbf20d4456050f0fe39c3f88f5246 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 16 May 2023 19:52:56 +0200 Subject: [PATCH 2/3] fuzz: add a new, more efficient, descriptor parsing target This new target focuses on fuzzing the actual descriptor parsing logic by not requiring the fuzzer to produce valid keys (nor a valid checksum for that matter). This should make it much more efficient to find bugs we could introduce moving forward. Using a character as a marker (here '%') to be able to search and replace in the string without having to mock the actual descriptor parsing logic was an insight from Pieter Wuille. --- src/test/fuzz/descriptor_parse.cpp | 116 +++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/test/fuzz/descriptor_parse.cpp b/src/test/fuzz/descriptor_parse.cpp index 0e4ef1522f6..0d3e422ff7e 100644 --- a/src/test/fuzz/descriptor_parse.cpp +++ b/src/test/fuzz/descriptor_parse.cpp @@ -3,11 +3,110 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include