diff --git a/libafl/src/bolts/fs.rs b/libafl/src/bolts/fs.rs index 8610554cf8..4b5e9b3a88 100644 --- a/libafl/src/bolts/fs.rs +++ b/libafl/src/bolts/fs.rs @@ -166,6 +166,6 @@ mod test { let two = one.clone(); one.write_buf("Welp".as_bytes()).unwrap(); drop(one); - assert_eq!("Welp", fs::read_to_string(&two.path).unwrap()); + assert_eq!("Welp", fs::read_to_string(two.path.as_path()).unwrap()); } } diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index 579a1a4997..af855c5ab3 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -366,7 +366,7 @@ const fn llmp_align(to_align: usize) -> usize { #[cfg(feature = "std")] #[inline] fn msg_offset_from_env(env_name: &str) -> Result, Error> { - let msg_offset_str = env::var(&format!("{env_name}_OFFSET"))?; + let msg_offset_str = env::var(format!("{env_name}_OFFSET"))?; Ok(if msg_offset_str == _NULL_ENV_STR { None } else { @@ -818,7 +818,7 @@ where #[cfg(feature = "std")] #[inline] fn client_id_from_env(env_name: &str) -> Result, Error> { - let client_id_str = env::var(&format!("{env_name}_CLIENT_ID"))?; + let client_id_str = env::var(format!("{env_name}_CLIENT_ID"))?; Ok(if client_id_str == _NULL_ENV_STR { None } else { @@ -829,7 +829,7 @@ where /// Writes the `id` to an env var #[cfg(feature = "std")] fn client_id_to_env(env_name: &str, id: ClientId) { - env::set_var(&format!("{env_name}_CLIENT_ID"), &format!("{id}")); + env::set_var(format!("{env_name}_CLIENT_ID"), format!("{id}")); } /// Reattach to a vacant `out_shmem`, to with a previous sender stored the information in an env before. @@ -1722,10 +1722,10 @@ where #[cfg(feature = "std")] pub unsafe fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), Error> { if msg.is_null() { - env::set_var(&format!("{map_env_name}_OFFSET"), _NULL_ENV_STR); + env::set_var(format!("{map_env_name}_OFFSET"), _NULL_ENV_STR); } else { env::set_var( - &format!("{map_env_name}_OFFSET"), + format!("{map_env_name}_OFFSET"), format!("{}", self.msg_to_offset(msg)?), ); } diff --git a/libafl/src/bolts/staterestore.rs b/libafl/src/bolts/staterestore.rs index 355b86b938..14d87ef295 100644 --- a/libafl/src/bolts/staterestore.rs +++ b/libafl/src/bolts/staterestore.rs @@ -37,7 +37,7 @@ impl StateShMemContent { slice::from_raw_parts(self.buf.as_ptr(), self.buf_len_checked(shmem_size)?) }; let filename = postcard::from_bytes::(bytes)?; - Some(temp_dir().join(&filename)) + Some(temp_dir().join(filename)) } else { None }) diff --git a/libafl/src/executors/command.rs b/libafl/src/executors/command.rs index fca9f6e6cf..4158250532 100644 --- a/libafl/src/executors/command.rs +++ b/libafl/src/executors/command.rs @@ -689,7 +689,7 @@ mod tests { })); let mut executor = - CommandExecutor::parse_afl_cmdline(&["file".to_string(), "@@".to_string()], (), true) + CommandExecutor::parse_afl_cmdline(["file".to_string(), "@@".to_string()], (), true) .unwrap(); executor .run_target( diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index 86e9102a25..43d175f534 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -594,7 +594,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> { None => OsString::from(".cur_input"), }; - let input_file = InputFile::create(&input_filename)?; + let input_file = InputFile::create(input_filename)?; let map = match &mut self.shmem_provider { None => None, @@ -677,7 +677,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> { )); } - println!("Autodict size {:x}", dict_size); + println!("Autodict size {dict_size:x}"); let (rlen, buf) = forkserver.read_st_size(dict_size as usize)?; diff --git a/libafl_cc/build.rs b/libafl_cc/build.rs index 49c555791f..1370e02a3d 100644 --- a/libafl_cc/build.rs +++ b/libafl_cc/build.rs @@ -80,7 +80,7 @@ fn find_llvm_config() -> Result { fn exec_llvm_config(args: &[&str]) -> String { let llvm_config = find_llvm_config().expect("Unexpected error"); - match Command::new(&llvm_config).args(args).output() { + match Command::new(llvm_config).args(args).output() { Ok(output) => String::from_utf8(output.stdout) .expect("Unexpected llvm-config output") .trim() @@ -161,7 +161,7 @@ fn main() { let src_dir = Path::new("src"); let dest_path = Path::new(&out_dir).join("clang_constants.rs"); - let mut clang_constants_file = File::create(&dest_path).expect("Could not create file"); + let mut clang_constants_file = File::create(dest_path).expect("Could not create file"); println!("cargo:rerun-if-env-changed=LLVM_CONFIG"); println!("cargo:rerun-if-env-changed=LIBAFL_EDGES_MAP_SIZE"); diff --git a/libafl_qemu/build_linux.rs b/libafl_qemu/build_linux.rs index 3602bc8635..d62f2b217e 100644 --- a/libafl_qemu/build_linux.rs +++ b/libafl_qemu/build_linux.rs @@ -1,4 +1,5 @@ use std::{env, fs, path::Path, process::Command}; + use which::which; const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge"; @@ -30,9 +31,9 @@ pub fn build() { assert_unique_feature!("usermode", "systemmode"); let emulation_mode = if cfg!(feature = "usermode") { "usermode".to_string() - }else if cfg!(feature = "systemmode") { + } else if cfg!(feature = "systemmode") { "systemmode".to_string() - }else{ + } else { env::var("EMULATION_MODE").unwrap_or_else(|_| { println!( "cargo:warning=No emulation mode feature enabled or EMULATION_MODE env specified for libafl_qemu, supported: usermode, systemmmode - defaulting to usermode" @@ -88,7 +89,11 @@ pub fn build() { // features at once (disabling the check for mutually exclusive options) // resulting in cpu_target being set to 'x86_64' above which obviously // doesn't support BE. - if cfg!(feature = "be") && cfg!(feature = "arm") && cfg!(feature = "usermode") && !cfg!(feature = "clippy"){ + if cfg!(feature = "be") + && cfg!(feature = "arm") + && cfg!(feature = "usermode") + && !cfg!(feature = "clippy") + { // We have told rustc which CPU target to use above (it doesn't need // to make any changes for endianness), however, we need QEMU to be // built for the right endian-ness, so we update the cpu_target for @@ -169,17 +174,16 @@ pub fn build() { let build_dir = qemu_path.join("build"); - let target_suffix = if emulation_mode == "usermode" { "linux-user".to_string() - }else{ + } else { "softmmu".to_string() }; let output_lib = if emulation_mode == "usermode" { - build_dir.join(&format!("libqemu-{cpu_target}.so")) - }else{ - build_dir.join(&format!("libqemu-system-{cpu_target}.so")) + build_dir.join(format!("libqemu-{cpu_target}.so")) + } else { + build_dir.join(format!("libqemu-system-{cpu_target}.so")) }; println!("cargo:rerun-if-changed={}", output_lib.to_string_lossy()); @@ -197,10 +201,15 @@ pub fn build() { //.arg("--as-static-lib") .arg("--as-shared-lib") .arg(&format!("--target-list={cpu_target}-{target_suffix}")) - .args(["--disable-blobs", "--disable-bsd-user", "--disable-fdt", "--disable-system"]) + .args([ + "--disable-blobs", + "--disable-bsd-user", + "--disable-fdt", + "--disable-system", + ]) .status() .expect("Configure failed"); - }else{ + } else { Command::new("./configure") .current_dir(&qemu_path) //.arg("--as-static-lib") @@ -338,7 +347,7 @@ pub fn build() { let mut objects = vec![]; for dir in &[ build_dir.join("libcommon.fa.p"), - build_dir.join(&format!("libqemu-{cpu_target}-{target_suffix}.fa.p")), + build_dir.join(format!("libqemu-{cpu_target}-{target_suffix}.fa.p")), ] { for path in fs::read_dir(dir).unwrap() { let path = path.unwrap().path(); @@ -379,7 +388,7 @@ pub fn build() { .arg("--end-group") .status() .expect("Partial linked failure"); - }else{ + } else { Command::new("ld") .current_dir(out_dir_path) .arg("-o") diff --git a/libafl_qemu/src/asan.rs b/libafl_qemu/src/asan.rs index 1e393f1d5a..17f6988f26 100644 --- a/libafl_qemu/src/asan.rs +++ b/libafl_qemu/src/asan.rs @@ -431,7 +431,7 @@ static mut ASAN_INITED: bool = false; pub fn init_with_asan(args: &mut Vec, env: &mut [(String, String)]) -> Emulator { assert!(!args.is_empty()); let current = env::current_exe().unwrap(); - let asan_lib = fs::canonicalize(¤t) + let asan_lib = fs::canonicalize(current) .unwrap() .parent() .unwrap() diff --git a/libafl_targets/build.rs b/libafl_targets/build.rs index def676a55d..b353c64f25 100644 --- a/libafl_targets/build.rs +++ b/libafl_targets/build.rs @@ -9,7 +9,7 @@ fn main() { let src_dir = Path::new("src"); let dest_path = Path::new(&out_dir).join("constants.rs"); - let mut constants_file = File::create(&dest_path).expect("Could not create file"); + let mut constants_file = File::create(dest_path).expect("Could not create file"); let edges_map_size: usize = option_env!("LIBAFL_EDGES_MAP_SIZE") .map_or(Ok(65536), str::parse)