fixed rust example

This commit is contained in:
Dominik Maier
2021-07-21 02:00:15 +02:00
parent a3a86afd0d
commit 3d7a2fc869
4 changed files with 26 additions and 22 deletions

View File

@ -226,6 +226,10 @@ pub mod wrappers {
} }
/// Internal function used in the macro /// Internal function used in the macro
///
/// # Safety
/// Dereferences the passed-in pointers up to `buf_size` bytes.
/// Should not be called directly.
pub unsafe fn afl_custom_fuzz_count_<M: RawCustomMutator>( pub unsafe fn afl_custom_fuzz_count_<M: RawCustomMutator>(
data: *mut c_void, data: *mut c_void,
buf: *const u8, buf: *const u8,
@ -278,6 +282,10 @@ pub mod wrappers {
} }
/// Internal function used in the macro /// Internal function used in the macro
///
/// # Safety
/// May dereference the passed-in `data` pointer.
/// Should not be called directly.
pub unsafe fn afl_custom_deinit_<M: RawCustomMutator>(data: *mut c_void) { pub unsafe fn afl_custom_deinit_<M: RawCustomMutator>(data: *mut c_void) {
match catch_unwind(|| { match catch_unwind(|| {
// drop the context // drop the context
@ -392,18 +400,16 @@ macro_rules! export_mutator {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn afl_custom_fuzz_count( pub unsafe extern "C" fn afl_custom_fuzz_count(
data: *mut ::std::os::raw::c_void, data: *mut ::std::os::raw::c_void,
buf: *const u8, buf: *const u8,
buf_size: usize, buf_size: usize,
) -> u32 { ) -> u32 {
unsafe { $crate::wrappers::afl_custom_fuzz_count_::<$mutator_type>(data, buf, buf_size)
$crate::wrappers::afl_custom_fuzz_count_::<$mutator_type>(data, buf, buf_size)
}
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn afl_custom_fuzz( pub unsafe extern "C" fn afl_custom_fuzz(
data: *mut ::std::os::raw::c_void, data: *mut ::std::os::raw::c_void,
buf: *mut u8, buf: *mut u8,
buf_size: usize, buf_size: usize,
@ -412,17 +418,15 @@ macro_rules! export_mutator {
add_buf_size: usize, add_buf_size: usize,
max_size: usize, max_size: usize,
) -> usize { ) -> usize {
unsafe { $crate::wrappers::afl_custom_fuzz_::<$mutator_type>(
$crate::wrappers::afl_custom_fuzz_::<$mutator_type>( data,
data, buf,
buf, buf_size,
buf_size, out_buf,
out_buf, add_buf,
add_buf, add_buf_size,
add_buf_size, max_size,
max_size, )
)
}
} }
#[no_mangle] #[no_mangle]
@ -430,7 +434,7 @@ macro_rules! export_mutator {
data: *mut ::std::os::raw::c_void, data: *mut ::std::os::raw::c_void,
filename_new_queue: *const ::std::os::raw::c_char, filename_new_queue: *const ::std::os::raw::c_char,
filename_orig_queue: *const ::std::os::raw::c_char, filename_orig_queue: *const ::std::os::raw::c_char,
) { ) -> bool {
$crate::wrappers::afl_custom_queue_new_entry_::<$mutator_type>( $crate::wrappers::afl_custom_queue_new_entry_::<$mutator_type>(
data, data,
filename_new_queue, filename_new_queue,
@ -462,8 +466,8 @@ macro_rules! export_mutator {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn afl_custom_deinit(data: *mut ::std::os::raw::c_void) { pub unsafe extern "C" fn afl_custom_deinit(data: *mut ::std::os::raw::c_void) {
unsafe { $crate::wrappers::afl_custom_deinit_::<$mutator_type>(data) } $crate::wrappers::afl_custom_deinit_::<$mutator_type>(data)
} }
}; };
} }