34 static std::vector<const char*>
g_args;
36 static void SetArgs(
int argc,
char** argv) {
37 for (
int i = 1; i < argc; ++i) {
40 if (strlen(argv[i]) > 2 && argv[i][0] ==
'-' && argv[i][1] ==
'-') {
50 std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize, TypeHidden>>&
FuzzTargets()
52 static std::map<std::string_view, std::tuple<TypeTestOneInput, TypeInitialize, TypeHidden>> g_fuzz_targets;
53 return g_fuzz_targets;
58 const auto it_ins =
FuzzTargets().try_emplace(
name, std::move(target), std::move(
init), hidden);
77 bool should_abort{
false};
78 if (std::getenv(
"PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
80 if (std::get<2>(
t.second))
continue;
81 std::cout <<
t.first << std::endl;
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};
89 if (std::get<2>(
t.second))
continue;
90 out_stream <<
t.first << std::endl;
100 std::get<1>(it->second)();
103 #if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
104 static bool read_stdin(std::vector<uint8_t>& data)
106 uint8_t buffer[1024];
108 while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) {
109 data.insert(data.end(), buffer, buffer + length);
119 test_one_input({data, size});
131 #if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
132 int main(
int argc,
char** argv)
145 while (__AFL_LOOP(1000)) {
146 std::vector<uint8_t> buffer;
147 if (!read_stdin(buffer)) {
150 test_one_input(buffer);
153 std::vector<uint8_t> buffer;
154 if (!read_stdin(buffer)) {
157 test_one_input(buffer);