14
14
15
15
#include < csignal>
16
16
#include < cstdint>
17
+ #include < cstdio>
18
+ #include < cstdlib>
19
+ #include < cstring>
17
20
#include < exception>
18
21
#include < fstream>
19
22
#include < functional>
23
+ #include < iostream>
20
24
#include < map>
21
25
#include < memory>
22
26
#include < string>
23
27
#include < tuple>
24
28
#include < unistd.h>
29
+ #include < utility>
25
30
#include < vector>
26
31
27
32
const std::function<void (const std::string&)> G_TEST_LOG_FUN{};
@@ -77,13 +82,13 @@ void initialize()
77
82
return WrappedGetAddrInfo (name, false );
78
83
};
79
84
80
- bool should_abort {false };
85
+ bool should_exit {false };
81
86
if (std::getenv (" PRINT_ALL_FUZZ_TARGETS_AND_ABORT" )) {
82
87
for (const auto & t : FuzzTargets ()) {
83
88
if (std::get<2 >(t.second )) continue ;
84
89
std::cout << t.first << std::endl;
85
90
}
86
- should_abort = true ;
91
+ should_exit = true ;
87
92
}
88
93
if (const char * out_path = std::getenv (" WRITE_ALL_FUZZ_TARGETS_AND_ABORT" )) {
89
94
std::cout << " Writing all fuzz target names to '" << out_path << " '." << std::endl;
@@ -92,13 +97,23 @@ void initialize()
92
97
if (std::get<2 >(t.second )) continue ;
93
98
out_stream << t.first << std::endl;
94
99
}
95
- should_abort = true ;
100
+ should_exit= true ;
101
+ }
102
+ if (should_exit){
103
+ std::exit (EXIT_SUCCESS);
104
+ }
105
+ if (const auto * env_fuzz{std::getenv (" FUZZ" )}) {
106
+ // To allow for easier fuzz executable binary modification,
107
+ static std::string g_copy{env_fuzz}; // create copy to avoid compiler optimizations, and
108
+ g_fuzz_target = g_copy.c_str (); // strip string after the first null-char.
109
+ } else {
110
+ std::cerr << " Must select fuzz target with the FUZZ env var." << std::endl;
111
+ std::cerr << " Hint: Set the PRINT_ALL_FUZZ_TARGETS_AND_ABORT=1 env var to see all compiled targets." << std::endl;
112
+ std::exit (EXIT_FAILURE);
96
113
}
97
- Assert (!should_abort);
98
- g_fuzz_target = Assert (std::getenv (" FUZZ" ));
99
114
const auto it = FuzzTargets ().find (g_fuzz_target);
100
115
if (it == FuzzTargets ().end ()) {
101
- std::cerr << " No fuzzer for " << g_fuzz_target << " ." << std::endl;
116
+ std::cerr << " No fuzz target compiled for " << g_fuzz_target << " ." << std::endl;
102
117
std::exit (EXIT_FAILURE);
103
118
}
104
119
Assert (!g_test_one_input);
0 commit comments