// Seeded smoke run of the session fuzz target (tests/fuzz/session_fuzz.cpp) on every // platform: random inputs, and mutations (bit flips, truncation, extension, byte // overwrites) of a valid encoding of every v4 message type. #include "evo/core/random.hpp" #include "evo/network/session_protocol.hpp" #include #include #include #include #include #include #include #include extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t*, std::size_t); namespace { using namespace evo::network; template std::vector> seeds(std::index_sequence) { return {encode_session(SessionMessage{std::in_place_index})...}; } } // namespace int main() { auto corpus = seeds(std::make_index_sequence>{}); std::size_t decodable = 0; for (const auto& s : corpus) decodable += decode_session(s).has_value(); evo::Random random{20261007}; const auto next = [&](std::size_t below) { return static_cast(random.next() % std::max(below, 1)); }; std::size_t inputs = 0; for (int round = 0; round < 4000; ++round) { for (const auto& seed : corpus) { auto input = seed; switch (next(5)) { case 0: // Flip bits. for (std::size_t k = 0, n = 1 + next(4); k < n && !input.empty(); ++k) input[next(input.size())] ^= static_cast(1U << next(8)); break; case 1: // Truncate. input.resize(next(input.size() + 1)); break; case 2: // Extend. for (std::size_t k = 0, n = 1 + next(32); k < n; ++k) input.push_back(static_cast(next(256))); break; case 3: // Overwrite a byte with an edge value. if (!input.empty()) input[next(input.size())] = std::array{0, 1, 0x7F, 0xFF}[next(4)]; break; default: // Random bytes. input.assign(next(300), 0); for (auto& b : input) b = static_cast(next(256)); } if (LLVMFuzzerTestOneInput(input.data(), input.size()) != 0) return 1; ++inputs; } } std::printf("session fuzz smoke inputs=%zu seeds=%zu decodable_seeds=%zu\n", inputs, corpus.size(), decodable); return 0; }