* 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();
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());
}
}

View File

@ -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<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 {
None
} else {
@ -818,7 +818,7 @@ where
#[cfg(feature = "std")]
#[inline]
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 {
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)?),
);
}

View File

@ -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::<String>(bytes)?;
Some(temp_dir().join(&filename))
Some(temp_dir().join(filename))
} else {
None
})

View File

@ -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(

View File

@ -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)?;

View File

@ -80,7 +80,7 @@ fn find_llvm_config() -> Result<String, String> {
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");

View File

@ -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")

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 {
assert!(!args.is_empty());
let current = env::current_exe().unwrap();
let asan_lib = fs::canonicalize(&current)
let asan_lib = fs::canonicalize(current)
.unwrap()
.parent()
.unwrap()

View File

@ -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)