* Autofix with new clippy

* Clippy
This commit is contained in:
Andrea Fioraldi 2022-10-26 09:41:08 +02:00 committed by GitHub
parent cf9c4188c0
commit 31077765de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 26 deletions

View File

@ -166,6 +166,6 @@ mod test {
let two = one.clone(); let two = one.clone();
one.write_buf("Welp".as_bytes()).unwrap(); one.write_buf("Welp".as_bytes()).unwrap();
drop(one); drop(one);
assert_eq!("Welp", fs::read_to_string(&two.path).unwrap()); assert_eq!("Welp", fs::read_to_string(two.path.as_path()).unwrap());
} }
} }

View File

@ -366,7 +366,7 @@ const fn llmp_align(to_align: usize) -> usize {
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[inline] #[inline]
fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, Error> { fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, 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 { Ok(if msg_offset_str == _NULL_ENV_STR {
None None
} else { } else {
@ -818,7 +818,7 @@ where
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[inline] #[inline]
fn client_id_from_env(env_name: &str) -> Result<Option<ClientId>, Error> { fn client_id_from_env(env_name: &str) -> Result<Option<ClientId>, 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 { Ok(if client_id_str == _NULL_ENV_STR {
None None
} else { } else {
@ -829,7 +829,7 @@ where
/// Writes the `id` to an env var /// Writes the `id` to an env var
#[cfg(feature = "std")] #[cfg(feature = "std")]
fn client_id_to_env(env_name: &str, id: ClientId) { 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. /// 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")] #[cfg(feature = "std")]
pub unsafe fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), Error> { pub unsafe fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), Error> {
if msg.is_null() { 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 { } else {
env::set_var( env::set_var(
&format!("{map_env_name}_OFFSET"), format!("{map_env_name}_OFFSET"),
format!("{}", self.msg_to_offset(msg)?), format!("{}", self.msg_to_offset(msg)?),
); );
} }

View File

@ -37,7 +37,7 @@ impl StateShMemContent {
slice::from_raw_parts(self.buf.as_ptr(), self.buf_len_checked(shmem_size)?) slice::from_raw_parts(self.buf.as_ptr(), self.buf_len_checked(shmem_size)?)
}; };
let filename = postcard::from_bytes::<String>(bytes)?; let filename = postcard::from_bytes::<String>(bytes)?;
Some(temp_dir().join(&filename)) Some(temp_dir().join(filename))
} else { } else {
None None
}) })

View File

@ -689,7 +689,7 @@ mod tests {
})); }));
let mut executor = let mut executor =
CommandExecutor::parse_afl_cmdline(&["file".to_string(), "@@".to_string()], (), true) CommandExecutor::parse_afl_cmdline(["file".to_string(), "@@".to_string()], (), true)
.unwrap(); .unwrap();
executor executor
.run_target( .run_target(

View File

@ -594,7 +594,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
None => OsString::from(".cur_input"), 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 { let map = match &mut self.shmem_provider {
None => None, 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)?; let (rlen, buf) = forkserver.read_st_size(dict_size as usize)?;

View File

@ -80,7 +80,7 @@ fn find_llvm_config() -> Result<String, String> {
fn exec_llvm_config(args: &[&str]) -> String { fn exec_llvm_config(args: &[&str]) -> String {
let llvm_config = find_llvm_config().expect("Unexpected error"); 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) Ok(output) => String::from_utf8(output.stdout)
.expect("Unexpected llvm-config output") .expect("Unexpected llvm-config output")
.trim() .trim()
@ -161,7 +161,7 @@ fn main() {
let src_dir = Path::new("src"); let src_dir = Path::new("src");
let dest_path = Path::new(&out_dir).join("clang_constants.rs"); 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=LLVM_CONFIG");
println!("cargo:rerun-if-env-changed=LIBAFL_EDGES_MAP_SIZE"); println!("cargo:rerun-if-env-changed=LIBAFL_EDGES_MAP_SIZE");

View File

@ -1,4 +1,5 @@
use std::{env, fs, path::Path, process::Command}; use std::{env, fs, path::Path, process::Command};
use which::which; use which::which;
const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge"; const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge";
@ -30,9 +31,9 @@ pub fn build() {
assert_unique_feature!("usermode", "systemmode"); assert_unique_feature!("usermode", "systemmode");
let emulation_mode = if cfg!(feature = "usermode") { let emulation_mode = if cfg!(feature = "usermode") {
"usermode".to_string() "usermode".to_string()
}else if cfg!(feature = "systemmode") { } else if cfg!(feature = "systemmode") {
"systemmode".to_string() "systemmode".to_string()
}else{ } else {
env::var("EMULATION_MODE").unwrap_or_else(|_| { env::var("EMULATION_MODE").unwrap_or_else(|_| {
println!( println!(
"cargo:warning=No emulation mode feature enabled or EMULATION_MODE env specified for libafl_qemu, supported: usermode, systemmmode - defaulting to usermode" "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) // features at once (disabling the check for mutually exclusive options)
// resulting in cpu_target being set to 'x86_64' above which obviously // resulting in cpu_target being set to 'x86_64' above which obviously
// doesn't support BE. // 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 // 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 // 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 // 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 build_dir = qemu_path.join("build");
let target_suffix = if emulation_mode == "usermode" { let target_suffix = if emulation_mode == "usermode" {
"linux-user".to_string() "linux-user".to_string()
}else{ } else {
"softmmu".to_string() "softmmu".to_string()
}; };
let output_lib = if emulation_mode == "usermode" { let output_lib = if emulation_mode == "usermode" {
build_dir.join(&format!("libqemu-{cpu_target}.so")) build_dir.join(format!("libqemu-{cpu_target}.so"))
}else{ } else {
build_dir.join(&format!("libqemu-system-{cpu_target}.so")) build_dir.join(format!("libqemu-system-{cpu_target}.so"))
}; };
println!("cargo:rerun-if-changed={}", output_lib.to_string_lossy()); println!("cargo:rerun-if-changed={}", output_lib.to_string_lossy());
@ -197,10 +201,15 @@ pub fn build() {
//.arg("--as-static-lib") //.arg("--as-static-lib")
.arg("--as-shared-lib") .arg("--as-shared-lib")
.arg(&format!("--target-list={cpu_target}-{target_suffix}")) .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() .status()
.expect("Configure failed"); .expect("Configure failed");
}else{ } else {
Command::new("./configure") Command::new("./configure")
.current_dir(&qemu_path) .current_dir(&qemu_path)
//.arg("--as-static-lib") //.arg("--as-static-lib")
@ -338,7 +347,7 @@ pub fn build() {
let mut objects = vec![]; let mut objects = vec![];
for dir in &[ for dir in &[
build_dir.join("libcommon.fa.p"), 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() { for path in fs::read_dir(dir).unwrap() {
let path = path.unwrap().path(); let path = path.unwrap().path();
@ -379,7 +388,7 @@ pub fn build() {
.arg("--end-group") .arg("--end-group")
.status() .status()
.expect("Partial linked failure"); .expect("Partial linked failure");
}else{ } else {
Command::new("ld") Command::new("ld")
.current_dir(out_dir_path) .current_dir(out_dir_path)
.arg("-o") .arg("-o")

View File

@ -431,7 +431,7 @@ static mut ASAN_INITED: bool = false;
pub fn init_with_asan(args: &mut Vec<String>, env: &mut [(String, String)]) -> Emulator { pub fn init_with_asan(args: &mut Vec<String>, env: &mut [(String, String)]) -> Emulator {
assert!(!args.is_empty()); assert!(!args.is_empty());
let current = env::current_exe().unwrap(); let current = env::current_exe().unwrap();
let asan_lib = fs::canonicalize(&current) let asan_lib = fs::canonicalize(current)
.unwrap() .unwrap()
.parent() .parent()
.unwrap() .unwrap()

View File

@ -9,7 +9,7 @@ fn main() {
let src_dir = Path::new("src"); let src_dir = Path::new("src");
let dest_path = Path::new(&out_dir).join("constants.rs"); 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") let edges_map_size: usize = option_env!("LIBAFL_EDGES_MAP_SIZE")
.map_or(Ok(65536), str::parse) .map_or(Ok(65536), str::parse)