diff --git a/libafl/src/corpus/mod.rs b/libafl/src/corpus/mod.rs index f90d7b3802..8e4917c225 100644 --- a/libafl/src/corpus/mod.rs +++ b/libafl/src/corpus/mod.rs @@ -175,7 +175,7 @@ pub trait Corpus: Sized { fn nth(&self, nth: usize) -> CorpusId { self.ids() .nth(nth) - .expect("Failed to get the {nth} CorpusId") + .unwrap_or_else(|| panic!("Failed to get the {nth} CorpusId")) } /// Get the nth corpus id; considers both enabled and disabled testcases diff --git a/libafl/src/events/llmp/mgr.rs b/libafl/src/events/llmp/mgr.rs index 63f0f7f5e2..5fac3c07e5 100644 --- a/libafl/src/events/llmp/mgr.rs +++ b/libafl/src/events/llmp/mgr.rs @@ -417,7 +417,7 @@ where + EvaluatorObservers::Input, S> + Evaluator::Input, S>, { - println!("Got event in client: {} from {:?}", event.name(), client_id); + log::trace!("Got event in client: {} from {client_id:?}", event.name()); if !self.hooks.pre_exec_all(state, client_id, &event)? { return Ok(()); } @@ -565,7 +565,7 @@ where #[cfg(not(feature = "llmp_compression"))] { self.llmp - .send_buf(LLMP_TAG_EVENT_TO_BOTH, &self.event_buffer[..written_len]); + .send_buf(LLMP_TAG_EVENT_TO_BOTH, &self.event_buffer[..written_len])?; } self.last_sent = current_time(); diff --git a/libafl/src/mutators/mod.rs b/libafl/src/mutators/mod.rs index 5b2de83bd4..93667b789d 100644 --- a/libafl/src/mutators/mod.rs +++ b/libafl/src/mutators/mod.rs @@ -353,7 +353,7 @@ impl MutatorsTuple for Vec>> { ) -> Result { let mutator = self .get_mut(index.0) - .ok_or_else(|| Error::key_not_found("Mutator with id {index:?} not found."))?; + .ok_or_else(|| Error::key_not_found(format!("Mutator with id {index:?} not found.")))?; mutator.mutate(state, input) } @@ -365,7 +365,7 @@ impl MutatorsTuple for Vec>> { ) -> Result<(), Error> { let mutator = self .get_mut(index) - .ok_or_else(|| Error::key_not_found("Mutator with id {index:?} not found."))?; + .ok_or_else(|| Error::key_not_found(format!("Mutator with id {index:?} not found.")))?; mutator.post_exec(state, new_corpus_id) } } diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index 5d5d3c8e12..23664f3d53 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -1059,7 +1059,7 @@ impl AFLppRedQueen { if buf_16 == pattern as u16 && another_buf_16 == another_pattern as u16 { let mut cloned = buf.to_vec(); cloned[buf_idx + 1] = (repl & 0xff) as u8; - cloned[buf_idx] = (repl >> 8 & 0xff) as u8; + cloned[buf_idx] = ((repl >> 8) & 0xff) as u8; vec.push(cloned); return Ok(true); } @@ -1074,9 +1074,9 @@ impl AFLppRedQueen { if buf_32 == pattern as u32 && another_buf_32 == another_pattern as u32 { let mut cloned = buf.to_vec(); cloned[buf_idx + 3] = (repl & 0xff) as u8; - cloned[buf_idx + 2] = (repl >> 8 & 0xff) as u8; - cloned[buf_idx + 1] = (repl >> 16 & 0xff) as u8; - cloned[buf_idx] = (repl >> 24 & 0xff) as u8; + cloned[buf_idx + 2] = ((repl >> 8) & 0xff) as u8; + cloned[buf_idx + 1] = ((repl >> 16) & 0xff) as u8; + cloned[buf_idx] = ((repl >> 24) & 0xff) as u8; vec.push(cloned); return Ok(true); @@ -1093,13 +1093,13 @@ impl AFLppRedQueen { let mut cloned = buf.to_vec(); cloned[buf_idx + 7] = (repl & 0xff) as u8; - cloned[buf_idx + 6] = (repl >> 8 & 0xff) as u8; - cloned[buf_idx + 5] = (repl >> 16 & 0xff) as u8; - cloned[buf_idx + 4] = (repl >> 24 & 0xff) as u8; - cloned[buf_idx + 3] = (repl >> 32 & 0xff) as u8; - cloned[buf_idx + 2] = (repl >> 32 & 0xff) as u8; - cloned[buf_idx + 1] = (repl >> 40 & 0xff) as u8; - cloned[buf_idx] = (repl >> 48 & 0xff) as u8; + cloned[buf_idx + 6] = ((repl >> 8) & 0xff) as u8; + cloned[buf_idx + 5] = ((repl >> 16) & 0xff) as u8; + cloned[buf_idx + 4] = ((repl >> 24) & 0xff) as u8; + cloned[buf_idx + 3] = ((repl >> 32) & 0xff) as u8; + cloned[buf_idx + 2] = ((repl >> 32) & 0xff) as u8; + cloned[buf_idx + 1] = ((repl >> 40) & 0xff) as u8; + cloned[buf_idx] = ((repl >> 48) & 0xff) as u8; vec.push(cloned); return Ok(true); diff --git a/libafl_frida/src/helper.rs b/libafl_frida/src/helper.rs index 278ba6f553..98d1fe3599 100644 --- a/libafl_frida/src/helper.rs +++ b/libafl_frida/src/helper.rs @@ -239,9 +239,10 @@ impl FridaInstrumentationHelperBuilder { let name = path .file_name() .and_then(|name| name.to_str()) - .expect("Failed to get script file name from path: {path:}"); + .unwrap_or_else(|| panic!("Failed to get script file name from path: {path:?}")); let script_prefix = include_str!("script.js"); - let file_contents = read_to_string(path).expect("Failed to read script: {path:}"); + let file_contents = read_to_string(path) + .unwrap_or_else(|err| panic!("Failed to read script {path:?}: {err:?}")); let payload = script_prefix.to_string() + &file_contents; let gum = Gum::obtain(); let backend = match backend { diff --git a/libafl_qemu/src/emu/hooks.rs b/libafl_qemu/src/emu/hooks.rs index 6f7a8b625e..53a6dc3350 100644 --- a/libafl_qemu/src/emu/hooks.rs +++ b/libafl_qemu/src/emu/hooks.rs @@ -182,13 +182,13 @@ where .push(Box::pin((InstructionHookId::invalid(), fat))); unsafe { - let hook_state = &mut self + let hook_state = &raw mut self .instruction_hooks .last_mut() .unwrap() .as_mut() .get_unchecked_mut() - .1 as *mut FatPtr; + .1; let id = self.qemu_hooks.add_instruction_hooks( &mut *hook_state, @@ -656,13 +656,13 @@ where self.backdoor_hooks .push(Box::pin((BackdoorHookId::invalid(), fat))); - let hook_state = &mut self + let hook_state = &raw mut self .backdoor_hooks .last_mut() .unwrap() .as_mut() .get_unchecked_mut() - .1 as *mut FatPtr; + .1; let id = self .qemu_hooks @@ -739,13 +739,13 @@ where self.new_thread_hooks .push(Box::pin((NewThreadHookId::invalid(), fat))); - let hook_state = &mut self + let hook_state = &raw mut self .new_thread_hooks .last_mut() .unwrap() .as_mut() .get_unchecked_mut() - .1 as *mut FatPtr; + .1; let id = self .qemu_hooks @@ -797,13 +797,13 @@ where self.pre_syscall_hooks .push(Box::pin((PreSyscallHookId::invalid(), fat))); - let hook_state = &mut self + let hook_state = &raw mut self .pre_syscall_hooks .last_mut() .unwrap() .as_mut() .get_unchecked_mut() - .1 as *mut FatPtr; + .1; let id = self .qemu_hooks @@ -848,13 +848,13 @@ where self.post_syscall_hooks .push(Box::pin((PostSyscallHookId::invalid(), fat))); - let hooks_state = &mut self + let hooks_state = &raw mut self .post_syscall_hooks .last_mut() .unwrap() .as_mut() .get_unchecked_mut() - .1 as *mut FatPtr; + .1; let id = self.qemu_hooks.add_post_syscall_hook( &mut *hooks_state, diff --git a/libafl_qemu/src/qemu/usermode.rs b/libafl_qemu/src/qemu/usermode.rs index e621adaf09..33b31e326c 100644 --- a/libafl_qemu/src/qemu/usermode.rs +++ b/libafl_qemu/src/qemu/usermode.rs @@ -286,7 +286,7 @@ pub mod pybind { a6: u64, a7: u64, ) -> SyscallHookResult { - unsafe { PY_SYSCALL_HOOK.as_ref() }.map_or_else( + unsafe { &*(&raw const PY_SYSCALL_HOOK).as_ref() }.map_or_else( || SyscallHookResult::new(None), |obj| { let args = (sys_num, a0, a1, a2, a3, a4, a5, a6, a7);