diff --git a/libafl/src/observers/cmp.rs b/libafl/src/observers/cmp.rs index af6ea17710..354a98e48e 100644 --- a/libafl/src/observers/cmp.rs +++ b/libafl/src/observers/cmp.rs @@ -103,7 +103,7 @@ pub trait CmpMap: Debug { fn usable_executions_for(&self, idx: usize) -> usize; /// Get the logged values for a cmp - fn values_of(&self, idx: usize, execution: usize) -> CmpValues; + fn values_of(&self, idx: usize, execution: usize) -> Option; /// Reset the state fn reset(&mut self) -> Result<(), Error>; @@ -150,24 +150,25 @@ where let mut last: Option = None; for j in 0..execs { - let val = self.cmp_map().values_of(i, j); - if let Some(l) = last.and_then(|x| x.to_u64_tuple()) { - if let Some(v) = val.to_u64_tuple() { - if l.0.wrapping_add(1) == v.0 { - increasing_v0 += 1; - } - if l.1.wrapping_add(1) == v.1 { - increasing_v1 += 1; - } - if l.0.wrapping_sub(1) == v.0 { - decreasing_v0 += 1; - } - if l.1.wrapping_sub(1) == v.1 { - decreasing_v1 += 1; + if let Some(val) = self.cmp_map().values_of(i, j) { + if let Some(l) = last.and_then(|x| x.to_u64_tuple()) { + if let Some(v) = val.to_u64_tuple() { + if l.0.wrapping_add(1) == v.0 { + increasing_v0 += 1; + } + if l.1.wrapping_add(1) == v.1 { + increasing_v1 += 1; + } + if l.0.wrapping_sub(1) == v.0 { + decreasing_v0 += 1; + } + if l.1.wrapping_sub(1) == v.1 { + decreasing_v1 += 1; + } } } + last = Some(val); } - last = Some(val); } // We check for execs-2 because the logged execs may wrap and have something like // 8 9 10 3 4 5 6 7 @@ -180,7 +181,9 @@ where } } for j in 0..execs { - meta.list.push(self.cmp_map().values_of(i, j)); + if let Some(val) = self.cmp_map().values_of(i, j) { + meta.list.push(val); + } } } } diff --git a/libafl_targets/src/cmplog.c b/libafl_targets/src/cmplog.c index a8e2977dce..fca6ab7fa7 100644 --- a/libafl_targets/src/cmplog.c +++ b/libafl_targets/src/cmplog.c @@ -111,12 +111,12 @@ void __libafl_targets_cmplog_routines(uintptr_t k, uint8_t *ptr1, uint8_t *ptr2) if (libafl_cmplog_map_ptr->headers[k].kind != CMPLOG_KIND_RTN) { libafl_cmplog_map_ptr->headers[k].kind = CMPLOG_KIND_RTN; libafl_cmplog_map_ptr->headers[k].hits = 1; - libafl_cmplog_map_ptr->headers[k].shape = len - 1; + libafl_cmplog_map_ptr->headers[k].shape = len; hits = 0; } else { hits = libafl_cmplog_map_ptr->headers[k].hits++; if (libafl_cmplog_map_ptr->headers[k].shape < len) - libafl_cmplog_map_ptr->headers[k].shape = len - 1; + libafl_cmplog_map_ptr->headers[k].shape = len; } hits &= CMPLOG_MAP_RTN_H - 1; diff --git a/libafl_targets/src/cmplog.rs b/libafl_targets/src/cmplog.rs index de49abb195..2e097561b3 100644 --- a/libafl_targets/src/cmplog.rs +++ b/libafl_targets/src/cmplog.rs @@ -110,35 +110,36 @@ impl CmpMap for CmpLogMap { } } - fn values_of(&self, idx: usize, execution: usize) -> CmpValues { + fn values_of(&self, idx: usize, execution: usize) -> Option { if self.headers[idx].kind == CMPLOG_KIND_INS { unsafe { match self.headers[idx].shape { - 1 => CmpValues::U8(( + 1 => Some(CmpValues::U8(( self.vals.operands[idx][execution].0 as u8, self.vals.operands[idx][execution].1 as u8, - )), - 2 => CmpValues::U16(( + ))), + 2 => Some(CmpValues::U16(( self.vals.operands[idx][execution].0 as u16, self.vals.operands[idx][execution].1 as u16, - )), - 4 => CmpValues::U32(( + ))), + 4 => Some(CmpValues::U32(( self.vals.operands[idx][execution].0 as u32, self.vals.operands[idx][execution].1 as u32, - )), - 8 => CmpValues::U64(( + ))), + 8 => Some(CmpValues::U64(( self.vals.operands[idx][execution].0, self.vals.operands[idx][execution].1, - )), - other => panic!("Invalid CmpLog shape {}", other), + ))), + // other => panic!("Invalid CmpLog shape {}", other), + _ => None, } } } else { unsafe { - CmpValues::Bytes(( + Some(CmpValues::Bytes(( self.vals.routines[idx][execution].0.to_vec(), self.vals.routines[idx][execution].1.to_vec(), - )) + ))) } } } diff --git a/scripts/clean_all.sh b/scripts/clean_all.sh new file mode 100755 index 0000000000..595a6f64c2 --- /dev/null +++ b/scripts/clean_all.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +cd "$SCRIPT_DIR/.." + +# TODO: This should be rewritten in rust, a Makefile, or some platform-independent language + +echo "Welcome to the happy clean script. :)" +echo "[*] Running clean for the main crates" +cargo clean + +fuzzers=$(find ./fuzzers -maxdepth 1 -type d) +backtrace_fuzzers=$(find ./fuzzers/backtrace_baby_fuzzers -maxdepth 1 -type d) + +for fuzzer in $(echo $fuzzers $backtrace_fuzzers); +do + pushd $fuzzer + echo "[*] Running clean for $fuzzer" + cargo clean + popd +done