| 62 | static TypeTestOneInput* g_test_one_input{nullptr}; |
| 63 | |
| 64 | void initialize() |
| 65 | { |
| 66 | // Terminate immediately if a fuzzing harness ever tries to create a TCP socket. |
| 67 | CreateSock = [](const CService&) -> std::unique_ptr<Sock> { std::terminate(); }; |
| 68 | |
| 69 | // Terminate immediately if a fuzzing harness ever tries to perform a DNS lookup. |
| 70 | g_dns_lookup = [](const std::string& name, bool allow_lookup) { |
| 71 | if (allow_lookup) { |
| 72 | std::terminate(); |
| 73 | } |
| 74 | return WrappedGetAddrInfo(name, false); |
| 75 | }; |
| 76 | |
| 77 | bool should_abort{false}; |
| 78 | if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) { |
| 79 | for (const auto& t : FuzzTargets()) { |
| 80 | if (std::get<2>(t.second)) continue; |
| 81 | std::cout << t.first << std::endl; |
| 82 | } |
| 83 | should_abort = true; |
| 84 | } |
| 85 | if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) { |
| 86 | std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl; |
| 87 | std::ofstream out_stream{out_path, std::ios::binary}; |
| 88 | for (const auto& t : FuzzTargets()) { |
| 89 | if (std::get<2>(t.second)) continue; |
| 90 | out_stream << t.first << std::endl; |
| 91 | } |
| 92 | should_abort = true; |
| 93 | } |
| 94 | Assert(!should_abort); |
| 95 | std::string_view fuzz_target{Assert(std::getenv("FUZZ"))}; |
| 96 | const auto it = FuzzTargets().find(fuzz_target); |
| 97 | Assert(it != FuzzTargets().end()); |
| 98 | Assert(!g_test_one_input); |
| 99 | g_test_one_input = &std::get<0>(it->second); |
| 100 | std::get<1>(it->second)(); |
| 101 | } |
| 102 | |
| 103 | #if defined(PROVIDE_FUZZ_MAIN_FUNCTION) |
| 104 | static bool read_stdin(std::vector<uint8_t>& data) |
no test coverage detected