Clippy fixes (#385)

* clippy fixes

* added missing use, switched to hashbrown

* fix

* more clippy
This commit is contained in:
Dominik Maier 2021-11-17 12:49:58 +01:00 committed by GitHub
parent 00d38dc535
commit 4d24012245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 30 deletions

View File

@ -99,7 +99,7 @@ extern "C" {
static mut ASAN_INITED: bool = false;
pub fn init_with_asan(args: &mut Vec<String>, env: &mut [(String, String)]) -> i32 {
assert!(args.len() > 0);
assert!(!args.is_empty());
let current = env::current_exe().unwrap();
let asan_lib = fs::canonicalize(&current)
.unwrap()
@ -117,7 +117,7 @@ pub fn init_with_asan(args: &mut Vec<String>, env: &mut [(String, String)]) -> i
for (k, v) in env.iter_mut() {
if k == "QEMU_SET_ENV" {
let mut new_v = vec![];
for e in v.split(",") {
for e in v.split(',') {
if e.starts_with("LD_PRELOAD=") {
added = true;
new_v.push(add_asan(e));
@ -129,11 +129,9 @@ pub fn init_with_asan(args: &mut Vec<String>, env: &mut [(String, String)]) -> i
}
}
for i in 0..args.len() {
if args[i] == "-E" && i + 1 < args.len() {
if args[i + 1].starts_with("LD_PRELOAD=") {
added = true;
args[i + 1] = add_asan(&args[i + 1])
}
if args[i] == "-E" && i + 1 < args.len() && args[i + 1].starts_with("LD_PRELOAD=") {
added = true;
args[i + 1] = add_asan(&args[i + 1]);
}
}
@ -158,7 +156,7 @@ pub struct QemuAsanHelper {
impl QemuAsanHelper {
#[must_use]
pub fn new() -> Self {
assert!(unsafe { ASAN_INITED == true }, "The ASan runtime is not initialized, use init_with_asan(...) instead of just init(...)");
assert!(unsafe { ASAN_INITED }, "The ASan runtime is not initialized, use init_with_asan(...) instead of just init(...)");
Self {
enabled: true,
filter: QemuInstrumentationFilter::None,
@ -216,6 +214,7 @@ impl QemuAsanHelper {
}
#[allow(clippy::unused_self)]
#[must_use]
pub fn is_poisoned(&self, addr: u64, size: usize) -> bool {
unsafe { asan_giovese_loadN(emu::g2h(addr), size) != 0 }
}
@ -454,6 +453,7 @@ pub fn trace_write_n_asan<I, QT, S>(
h.read_n(addr, size);
}
#[allow(clippy::too_many_arguments)]
pub fn qasan_fake_syscall<I, QT, S>(
helpers: &mut QT,
_state: &mut S,

View File

@ -1,9 +1,9 @@
use hashbrown::{hash_map::Entry, HashMap};
use libafl::{executors::ExitKind, inputs::Input, observers::ObserversTuple, state::HasMetadata};
pub use libafl_targets::{
cmplog::__libafl_targets_cmplog_instructions, CmpLogObserver, CMPLOG_MAP, CMPLOG_MAP_W,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::{
emu,
@ -101,13 +101,11 @@ where
.get_mut::<QemuCmpsMapMetadata>()
.unwrap();
let id = meta.current_id as usize;
if meta.map.contains_key(&pc) {
Some(*meta.map.get(&pc).unwrap())
} else {
Some(*meta.map.entry(pc).or_insert_with(|| {
meta.current_id = ((id + 1) & (CMPLOG_MAP_W - 1)) as u64;
meta.map.insert(pc, id as u64);
Some(id as u64)
}
id as u64
}))
}
pub extern "C" fn trace_cmp1_cmplog(id: u64, v0: u8, v1: u8) {

View File

@ -1,7 +1,8 @@
use hashbrown::{hash_map::Entry, HashMap};
use libafl::{executors::ExitKind, inputs::Input, observers::ObserversTuple, state::HasMetadata};
pub use libafl_targets::{EDGES_MAP, EDGES_MAP_SIZE, MAX_EDGES_NUM};
use serde::{Deserialize, Serialize};
use std::{cell::UnsafeCell, cmp::max, collections::HashMap};
use std::{cell::UnsafeCell, cmp::max};
use crate::{
emu,
@ -104,21 +105,25 @@ where
.metadata_mut()
.get_mut::<QemuEdgesMapMetadata>()
.unwrap();
if meta.map.contains_key(&(src, dest)) {
let id = *meta.map.get(&(src, dest)).unwrap();
let nxt = (id as usize + 1) & (EDGES_MAP_SIZE - 1);
unsafe {
MAX_EDGES_NUM = max(MAX_EDGES_NUM, nxt);
match meta.map.entry((src, dest)) {
Entry::Occupied(e) => {
let id = *e.get();
let nxt = (id as usize + 1) & (EDGES_MAP_SIZE - 1);
unsafe {
MAX_EDGES_NUM = max(MAX_EDGES_NUM, nxt);
}
Some(id)
}
Some(id)
} else {
let id = meta.current_id;
meta.map.insert((src, dest), id);
meta.current_id = (id + 1) & (EDGES_MAP_SIZE as u64 - 1);
unsafe {
MAX_EDGES_NUM = meta.current_id as usize;
Entry::Vacant(e) => {
let id = meta.current_id;
e.insert(id);
meta.current_id = (id + 1) & (EDGES_MAP_SIZE as u64 - 1);
unsafe {
MAX_EDGES_NUM = meta.current_id as usize;
}
Some(id as u64)
}
Some(id as u64)
}
}

View File

@ -232,7 +232,7 @@ extern "C" {
#[allow(clippy::must_use_candidate, clippy::similar_names)]
pub fn init(args: &[String], env: &[(String, String)]) -> i32 {
assert!(args.len() > 0);
assert!(!args.is_empty());
let args: Vec<String> = args.iter().map(|x| x.clone() + "\0").collect();
let argv: Vec<*const u8> = args.iter().map(|x| x.as_bytes().as_ptr()).collect();
assert!(argv.len() < i32::MAX as usize);