diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2020-03-27 14:12:11 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2020-03-29 13:17:04 +0000 |
commit | a16ea051f915eb4c975fe06f89470aa99d99d7e4 (patch) | |
tree | afe177b87d4507e3fa606186a80aade4f2fed339 /src/test | |
parent | bdc2644b72d68b52383bb461ccd6ef8448674cea (diff) |
tests: Add fuzzing harness for functions/classes in flatfile.h
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/flatfile.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/fuzz/flatfile.cpp b/src/test/fuzz/flatfile.cpp new file mode 100644 index 0000000000..a55de77df7 --- /dev/null +++ b/src/test/fuzz/flatfile.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <flatfile.h> +#include <optional.h> +#include <test/fuzz/FuzzedDataProvider.h> +#include <test/fuzz/fuzz.h> +#include <test/fuzz/util.h> + +#include <cassert> +#include <cstdint> +#include <string> +#include <vector> + +void test_one_input(const std::vector<uint8_t>& buffer) +{ + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); + Optional<FlatFilePos> flat_file_pos = ConsumeDeserializable<FlatFilePos>(fuzzed_data_provider); + if (!flat_file_pos) { + return; + } + Optional<FlatFilePos> another_flat_file_pos = ConsumeDeserializable<FlatFilePos>(fuzzed_data_provider); + if (another_flat_file_pos) { + assert((*flat_file_pos == *another_flat_file_pos) != (*flat_file_pos != *another_flat_file_pos)); + } + (void)flat_file_pos->ToString(); + flat_file_pos->SetNull(); + assert(flat_file_pos->IsNull()); +} |