8000 Refactoring · rust-fuzz/libfuzzer@ba4ad43 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba4ad43

Browse files
committed
Refactoring
1 parent e793413 commit ba4ad43

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

src/lib.rs

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,24 @@ pub fn rust_libfuzzer_debug_path() -> &'static Option<String> {
7878
RUST_LIBFUZZER_DEBUG_PATH.get_or_init(|| std::env::var("RUST_LIBFUZZER_DEBUG_PATH").ok())
7979
}
8080

81-
/* #[doc(hidden)]
82-
#[export_name = "LLVMFuzzerInitialize"]
81+
#[doc(hidden)]
82+
//#[export_name = "LLVMFuzzerInitialize"]
8383
pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize {
84+
// Registers a panic hook that aborts the process before unwinding.
85+
// It is useful to abort before unwinding so that the fuzzer will then be
86+
// able to analyse the process stack frames to tell different bugs appart.
87+
//
88+
// HACK / FIXME: it would be better to use `-C panic=abort` but it's currently
89+
// impossible to build code using compiler plugins with this flag.
90+
// We will be able to remove this code when
91+
// https://github.com/rust-lang/cargo/issues/5423 is fixed.
92+
let default_hook = std::panic::take_hook();
93+
std::panic::set_hook(Box::new(move |panic_info| {
94+
default_hook(panic_info);
95+
std::process::abort();
96+
}));
8497
0
85-
} */
98+
}
8699

87100
/// Define a fuzz target.
88101
///
@@ -191,19 +204,7 @@ macro_rules! fuzz_target {
191204
/// LLVMFuzzerInitialize is called once before the fuzzer starts.
192205
#[no_mangle]
193206
pub extern "C" fn LLVMFuzzerInitialize(_argc: *const isize, _argv: *const *const *const u8) -> isize {
194-
// Registers a panic hook that aborts the process before unwinding.
195-
// It is useful to abort before unwinding so that the fuzzer will then be
196-
// able to analyse the process stack frames to tell different bugs appart.
197-
//
198-
// HACK / FIXME: it would be better to use `-C panic=abort` but it's currently
199-
// impossible to build code using compiler plugins with this flag.
200-
// We will be able to remove this code when
201-
// https://github.com/rust-lang/cargo/issues/5423 is fixed.
202-
let default_hook = std::panic::take_hook();
203-
std::panic::set_hook(Box::new(move |panic_info| {
204-
default_hook(panic_info);
205-
std::process::abort();
206-
}));
207+
$crate::initialize(_argc, _argv);
207208

208209
// Supplied init code
209210
$init;
@@ -275,19 +276,7 @@ macro_rules! fuzz_target {
275276
/// LLVMFuzzerInitialize is called once before the fuzzer starts.
276277
#[no_mangle]
277278
pub extern "C" fn LLVMFuzzerInitialize(_argc: *const isize, _argv: *const *const *const u8) -> isize {
278-
// Registers a panic hook that aborts the process before unwinding.
279-
// It is useful to abort before unwinding so that the fuzzer will then be
280-
// able to analyse the process stack frames to tell different bugs appart.
281-
//
282-
// HACK / FIXME: it would be better to use `-C panic=abort` but it's currently
283-
// impossible to build code using compiler plugins with this flag.
284-
// We will be able to remove this code when
285-
// https://github.com/rust-lang/cargo/issues/5423 is fixed.
286-
let default_hook = std::panic::take_hook();
287-
std::panic::set_hook(Box::new(move |panic_info| {
288-
default_hook(panic_info);
289-
std::process::abort();
290-
}));
279+
$crate::initialize(_argc, _argv);
291280

292281
// Supplied init code
293282
$init;

0 commit comments

Comments
 (0)
0