diff options
author | Dominik Maier <domenukk@gmail.com> | 2021-07-21 01:44:27 +0200 |
---|---|---|
committer | Dominik Maier <domenukk@gmail.com> | 2021-07-21 01:44:27 +0200 |
commit | a3a86afd0db5bf90d6bc1dc5f58d07e6bc7202c8 (patch) | |
tree | 2ddcf7fde2f476d8b4f04cead6c2d31cef3cef4d | |
parent | 4d7c23e2312236b20a61531c70df297a35455822 (diff) | |
download | afl++-a3a86afd0db5bf90d6bc1dc5f58d07e6bc7202c8.tar.gz |
fix rust mutator bindingsbuild
-rw-r--r-- | custom_mutators/rust/custom_mutator/src/lib.rs | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/custom_mutators/rust/custom_mutator/src/lib.rs b/custom_mutators/rust/custom_mutator/src/lib.rs index 6826623f..39c2b453 100644 --- a/custom_mutators/rust/custom_mutator/src/lib.rs +++ b/custom_mutators/rust/custom_mutator/src/lib.rs @@ -53,7 +53,11 @@ pub trait RawCustomMutator { 1 } - fn queue_new_entry(&mut self, filename_new_queue: &Path, _filename_orig_queue: Option<&Path>) -> bool { + fn queue_new_entry( + &mut self, + filename_new_queue: &Path, + _filename_orig_queue: Option<&Path>, + ) -> bool { false } @@ -86,7 +90,6 @@ pub mod wrappers { use std::{ any::Any, - convert::TryInto, ffi::{c_void, CStr, OsStr}, mem::ManuallyDrop, os::{raw::c_char, unix::ffi::OsStrExt}, @@ -178,6 +181,10 @@ pub mod wrappers { } /// Internal function used in the macro + /// # Safety + /// + /// May dereference all passed-in pointers. + /// Should not be called manually, but will be called by `afl-fuzz` pub unsafe fn afl_custom_fuzz_<M: RawCustomMutator>( data: *mut c_void, buf: *mut u8, @@ -201,13 +208,10 @@ pub mod wrappers { } else { Some(slice::from_raw_parts(add_buf, add_buf_size)) }; - match context - .mutator - .fuzz(buff_slice, add_buff_slice, max_size.try_into().unwrap()) - { + match context.mutator.fuzz(buff_slice, add_buff_slice, max_size) { Some(buffer) => { *out_buf = buffer.as_ptr(); - buffer.len().try_into().unwrap() + buffer.len() } None => { // return the input buffer with 0-length to let AFL skip this mutation attempt @@ -266,7 +270,7 @@ pub mod wrappers { }; context .mutator - .queue_new_entry(filename_new_queue, filename_orig_queue); + .queue_new_entry(filename_new_queue, filename_orig_queue) }) { Ok(ret) => ret, Err(err) => panic_handler("afl_custom_queue_new_entry", err), @@ -544,8 +548,8 @@ pub trait CustomMutator { &mut self, filename_new_queue: &Path, filename_orig_queue: Option<&Path>, - ) -> Result<(), Self::Error> { - Ok(()) + ) -> Result<bool, Self::Error> { + Ok(false) } fn queue_get(&mut self, filename: &Path) -> Result<bool, Self::Error> { @@ -619,11 +623,16 @@ where } } - fn queue_new_entry(&mut self, filename_new_queue: &Path, filename_orig_queue: Option<&Path>) -> bool { + fn queue_new_entry( + &mut self, + filename_new_queue: &Path, + filename_orig_queue: Option<&Path>, + ) -> bool { match self.queue_new_entry(filename_new_queue, filename_orig_queue) { Ok(r) => r, Err(e) => { Self::handle_error(e); + false } } } @@ -698,16 +707,14 @@ mod default_mutator_describe { fn truncate_str_unicode_safe(s: &str, max_len: usize) -> &str { if s.len() <= max_len { s + } else if let Some((last_index, _)) = s + .char_indices() + .take_while(|(index, _)| *index <= max_len) + .last() + { + &s[..last_index] } else { - if let Some((last_index, _)) = s - .char_indices() - .take_while(|(index, _)| *index <= max_len) - .last() - { - &s[..last_index] - } else { - "" - } + "" } } |