Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions fuzzer/src/depot/depot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
atomic::{AtomicUsize, Ordering},
Mutex, RwLock,
},
time::{SystemTime, UNIX_EPOCH},
};
// https://crates.io/crates/priority-queue
use angora_common::config;
Expand All @@ -23,6 +24,14 @@ pub struct Depot {
pub num_crashes: AtomicUsize,
pub dirs: DepotDir,
pub cfg: RwLock<ControlFlowGraph>,
pub start_time: u128,
}

macro_rules! get_cur_time {
() => {{
SystemTime::now().duration_since(UNIX_EPOCH)
.expect("Cannot get timestamp").as_millis()
}}
}

impl Depot {
Expand All @@ -33,7 +42,7 @@ impl Depot {
num_hangs: AtomicUsize::new(0),
num_crashes: AtomicUsize::new(0),
dirs: DepotDir::new(in_dir, out_dir),
cfg
cfg, start_time: get_cur_time!()
}
}

Expand All @@ -43,6 +52,7 @@ impl Depot {
num: &AtomicUsize,
cmpid: u32,
dir: &Path,
time: Option<u128>
) -> usize {
let id = num.fetch_add(1, Ordering::Relaxed);
trace!(
Expand All @@ -51,7 +61,7 @@ impl Depot {
status,
cmpid
);
let new_path = get_file_name(dir, id);
let new_path = get_file_name(dir, id, time);
let mut f = fs::File::create(new_path.as_path()).expect("Could not save new input file.");
f.write_all(buf)
.expect("Could not write seed buffer to file.");
Expand All @@ -62,17 +72,18 @@ impl Depot {
pub fn save(&self, status: StatusType, buf: &Vec<u8>, cmpid: u32) -> usize {
match status {
StatusType::Normal => {
Self::save_input(&status, buf, &self.num_inputs, cmpid, &self.dirs.inputs_dir)
Self::save_input(&status, buf, &self.num_inputs, cmpid, &self.dirs.inputs_dir, None)
},
StatusType::Timeout => {
Self::save_input(&status, buf, &self.num_hangs, cmpid, &self.dirs.hangs_dir)
Self::save_input(&status, buf, &self.num_hangs, cmpid, &self.dirs.hangs_dir, None)
},
StatusType::Crash => Self::save_input(
&status,
buf,
&self.num_crashes,
cmpid,
&self.dirs.crashes_dir,
Some(get_cur_time!() - self.start_time)
),
_ => 0,
}
Expand All @@ -87,7 +98,7 @@ impl Depot {
}

pub fn get_input_buf(&self, id: usize) -> Vec<u8> {
let path = get_file_name(&self.dirs.inputs_dir, id);
let path = get_file_name(&self.dirs.inputs_dir, id, None);
read_from_file(&path)
}

Expand Down
7 changes: 5 additions & 2 deletions fuzzer/src/depot/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use std::{
path::{Path, PathBuf},
};

pub fn get_file_name(dir: &Path, id: usize) -> PathBuf {
let file_name = format!("id:{:06}", id);
pub fn get_file_name(dir: &Path, id: usize, time: Option<u128>) -> PathBuf {
let file_name = match time {
Some(t) => format!("id:{:06},{}", id, t),
None => format!("id:{:06}", id)
};
dir.join(file_name)
}

Expand Down
8 changes: 7 additions & 1 deletion tools/llvm-diff-parmesan/id-assigner-pass/src/IDAssigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Constant *ParmeSanDummyCall;
void IDAssigner::collectCallSiteDominators(Function *F) {
for (auto &BB : *F) {
CallSiteIdType PrevCallSiteId;
bool HasPrevCallSiteId = false;
for (auto &I : BB) {
if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
Value *V = SI->getPointerOperand();
Expand All @@ -102,6 +103,7 @@ void IDAssigner::collectCallSiteDominators(Function *F) {
if (CV) {
if (ConstantInt *ConstInt = dyn_cast<ConstantInt>(CV)) {
PrevCallSiteId = ConstInt->getZExtValue();
HasPrevCallSiteId = true;
}
}
}
Expand Down Expand Up @@ -130,7 +132,8 @@ void IDAssigner::collectCallSiteDominators(Function *F) {
}

}
CallSiteDominatorsMap[PrevCallSiteId] = CSDominatorCmpIds;
if (HasPrevCallSiteId)
CallSiteDominatorsMap[PrevCallSiteId] = CSDominatorCmpIds;

}
}
Expand Down Expand Up @@ -434,6 +437,9 @@ void IDAssigner::addCustomTargetsFromFile(const std::string Path, Module *M) {
static const std::string Xlibs("/usr/");
if (filename.empty() || line == 0 || !filename.compare(0, Xlibs.size(), Xlibs))
continue;
std::size_t found0 = filename.find_last_of("/\\");
if (found0 != std::string::npos)
filename = filename.substr(found0 + 1);
for (auto &target : targets) {
std::size_t found = target.find_last_of("/\\");
if (found != std::string::npos)
Expand Down