aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/util.h
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-03-15 14:08:34 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-03-15 16:25:29 +0000
commit44abf417eb1cd8598084eee1a429ca57c7d0579a (patch)
treee9cedaf6130356aafacc19d98d04d0ffbe0a1329 /src/test/fuzz/util.h
parentd69145acb76ff12b7c5c1e55ce89e14bc6453904 (diff)
tests: Add fuzzing harness for various functions taking std::string as input
Diffstat (limited to 'src/test/fuzz/util.h')
-rw-r--r--src/test/fuzz/util.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h
index ff278aebcc..47f8d3fb27 100644
--- a/src/test/fuzz/util.h
+++ b/src/test/fuzz/util.h
@@ -25,6 +25,16 @@ NODISCARD inline std::vector<uint8_t> ConsumeRandomLengthByteVector(FuzzedDataPr
return {s.begin(), s.end()};
}
+NODISCARD inline std::vector<std::string> ConsumeRandomLengthStringVector(FuzzedDataProvider& fuzzed_data_provider, size_t max_vector_size = 16, size_t max_string_length = 16) noexcept
+{
+ const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);
+ std::vector<std::string> r;
+ for (size_t i = 0; i < n_elements; ++i) {
+ r.push_back(fuzzed_data_provider.ConsumeRandomLengthString(max_string_length));
+ }
+ return r;
+}
+
template <typename T>
NODISCARD inline Optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, size_t max_length = 4096) noexcept
{