Skip to content

Commit

Permalink
fix: make clippy partially happy
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-abel committed Jan 3, 2025
1 parent a15ed21 commit b17ab00
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 66 deletions.
6 changes: 3 additions & 3 deletions src/addrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ impl From<u64> for VirtAddr {
}
}

impl Into<u64> for VirtAddr {
fn into(self) -> u64 {
self.0
impl From<VirtAddr> for u64 {
fn from(val: VirtAddr) -> Self {
val.0
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ProjectState {
// The coverage left to hit
let coverage_left = breakpoints
.keys()
.filter(|a| prev_coverage.code_cov.get(&a).cloned().unwrap_or(0u16) == 0)
.filter(|a| prev_coverage.code_cov.get(a).cloned().unwrap_or(0u16) == 0)
.copied()
.collect();

Expand Down
18 changes: 9 additions & 9 deletions src/commands/corpus_min.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ pub(crate) fn run<FUZZER: Fuzzer>(
// Get the variables for this thread
let paths = paths.clone();
let path_index = path_index.clone();
let vbcpu = project_state.vbcpu.clone();
let vbcpu = project_state.vbcpu;
let cpuids = cpuids.clone();
let physmem_file_fd = physmem_file.as_raw_fd();
let config = project_state.config.clone();
let symbols = symbols.clone();
let symbol_breakpoints = symbol_breakpoints.clone();
let covbp_bytes = covbp_bytes.clone();
let timeout = args.timeout.clone();
let timeout = args.timeout;
let clean_snapshot = clean_snapshot.clone();
let project_dir = project_state.path.clone();

Expand Down Expand Up @@ -251,7 +251,7 @@ pub(crate) fn run<FUZZER: Fuzzer>(
);

let coverage_lcov = project_state.path.clone().join("coverage_min.lcov.info");
if let Ok(debug_info) = crate::stats::DebugInfo::new(&project_state) {
if let Ok(debug_info) = crate::stats::DebugInfo::new(project_state) {
let mut lcov = debug_info.empty_lcov_info();
debug_info.update_lcov_addresses(
&mut lcov,
Expand Down Expand Up @@ -421,7 +421,7 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
result.insert(curr_index, coverage);

// Reset the guest state
let _perf = fuzzvm.reset_guest_state(&mut fuzzer)?;
fuzzvm.reset_guest_state(&mut fuzzer)?;

// Reset the fuzzer state
fuzzer.reset_fuzzer_state();
Expand Down Expand Up @@ -473,15 +473,15 @@ impl CorpusMinimizer {
pub fn size(&self) {
let sum: usize = self
.addr_to_inputs
.iter()
.map(|(_k, v)| std::mem::size_of::<u64>() + v.len() * size_of::<usize>())
.values()
.map(|v| std::mem::size_of::<u64>() + v.len() * size_of::<usize>())
.sum();
log::info!("Size of addr_to_inputs: {}", get_byte_size(sum as u64));

let sum: usize = self
.input_coverage
.iter()
.map(|(_k, v)| std::mem::size_of::<u64>() + v.len() * size_of::<u64>())
.values()
.map(|v| std::mem::size_of::<u64>() + v.len() * size_of::<u64>())
.sum();
log::info!("Size of input_coverage: {}", get_byte_size(sum as u64));
}
Expand Down Expand Up @@ -555,7 +555,7 @@ impl CorpusMinimizer {
}

// Return the removed path indexes
let trash = self.input_coverage.keys().map(|x| *x).collect();
let trash = self.input_coverage.keys().copied().collect();

// Replace the current minimizer with the newly created one
*self = new_minimizer;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
u64::try_from(core_id.id)?,
&mut fuzzer,
vm,
&vbcpu,
vbcpu,
cpuid,
snapshot_fd.as_raw_fd(),
clean_snapshot,
Expand All @@ -137,7 +137,7 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
)?;

// Get the input to trace
let input = InputWithMetadata::from_path(input_case, &project_dir)?;
let input = InputWithMetadata::from_path(input_case, project_dir)?;

log::info!(
"gathering coverage for input {} with timeout: {:?}",
Expand Down Expand Up @@ -193,7 +193,7 @@ pub(crate) fn start_core<FUZZER: Fuzzer>(
);
crate::stats::write_lighthouse_coverage(&project_state.modules, &feedback, &lighthouse_file)?;

if let Ok(debug_info) = crate::stats::DebugInfo::new(&project_state) {
if let Ok(debug_info) = crate::stats::DebugInfo::new(project_state) {
// Get the lcov coverage file
let coverage_lcov = coverage_dir.join(format!("{orig_file_name}.lcov.info"));
log::info!("Writing lcov coverage to {}", coverage_lcov.display());
Expand Down
12 changes: 6 additions & 6 deletions src/commands/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn start_core<FUZZER: Fuzzer>(
let redqueen_breakpoints = None;

use MinimizeCodeCovLevel::{BasicBlock, Hitcounts};
if matches!(min_params.codecov_level, Hitcounts | BasicBlock) && !coverage_breakpoints.is_some()
if matches!(min_params.codecov_level, Hitcounts | BasicBlock) && coverage_breakpoints.is_none()
{
anyhow::bail!("code coverage level requires breakpoint addresses!");
}
Expand Down Expand Up @@ -146,7 +146,7 @@ fn start_core<FUZZER: Fuzzer>(

// Get the initial input

let input_bytes = std::fs::read(&input_fuzzcase)?;
let input_bytes = std::fs::read(input_fuzzcase)?;
let start_input_size = input_bytes.len();

let starting_input: InputWithMetadata<FUZZER::Input> =
Expand Down Expand Up @@ -437,7 +437,7 @@ fn start_core<FUZZER: Fuzzer>(
);

log::info!("Writing minimized file: {:?}", output_fuzzcase);
std::fs::write(&output_fuzzcase, &result_bytes)?;
std::fs::write(output_fuzzcase, &result_bytes)?;

if min_params.dump_feedback {
if let Some(feedback) = last_feedback {
Expand All @@ -453,7 +453,7 @@ fn start_core<FUZZER: Fuzzer>(
if last_execution.is_crash() {
// Allow the fuzzer to handle the crashing state
// Useful for things like syscall fuzzer to write a C file from the input
fuzzer.handle_crash(&input, &mut fuzzvm, &output_fuzzcase)?;
fuzzer.handle_crash(&input, &mut fuzzvm, output_fuzzcase)?;
}

Ok(())
Expand Down Expand Up @@ -562,12 +562,12 @@ pub(crate) fn run<FUZZER: Fuzzer>(
&symbols,
symbol_breakpoints.as_ref(),
covbps.as_ref(),
&infile,
infile,
&outfile,
args.timeout,
args.iterations_per_stage,
project_state.config.clone(),
minparams.clone(),
minparams,
&project_state.path,
)?;
minimized += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub(crate) fn run(project_state: &ProjectState, args: &cmdline::Project) -> Resu
project_state
.coverage_basic_blocks
.as_ref()
.and_then(|covbps| Some(covbps.len()))
.map(|covbps| covbps.len())
.unwrap_or(0_usize)
);
let filepath = project_state.path.join("debug_info.json");
Expand Down
33 changes: 15 additions & 18 deletions src/commands/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,24 +347,21 @@ fn start_core<FUZZER: Fuzzer>(
if translation.phys_addr().is_some()
&& translation.is_executable()
&& !translation.is_writable()
&& !fuzzvm.has_breakpoint(retaddr, fuzzvm.cr3())
{
if !fuzzvm.has_breakpoint(retaddr, fuzzvm.cr3()) {
log::debug!("setting retaddr breakpoint for newly discovered return address {retaddr:?}");
// set breakpoint at callsite
let res = fuzzvm.set_breakpoint(
retaddr,
fuzzvm.cr3(),
BreakpointType::Repeated,
BreakpointMemory::NotDirty,
BreakpointHook::Ignore,
);
match res {
Ok(_) => {}
Err(e) => {
log::debug!(
"invalid retaddr breakpoint @ {retaddr:?} {e:?}"
);
}
log::debug!("setting retaddr breakpoint for newly discovered return address {retaddr:?}");
// set breakpoint at callsite
let res = fuzzvm.set_breakpoint(
retaddr,
fuzzvm.cr3(),
BreakpointType::Repeated,
BreakpointMemory::NotDirty,
BreakpointHook::Ignore,
);
match res {
Ok(_) => {}
Err(e) => {
log::debug!("invalid retaddr breakpoint @ {retaddr:?} {e:?}");
}
}
}
Expand Down Expand Up @@ -624,7 +621,7 @@ fn start_core<FUZZER: Fuzzer>(
if single_step {
trace_file.set_file_name(format!("{orig_file_name}_trace"));
} else {
trace_file.set_file_name(&format!("{orig_file_name}_trace.no_single_step"));
trace_file.set_file_name(format!("{orig_file_name}_trace.no_single_step"));
}

trace_file
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4418,7 +4418,7 @@ impl<'a, FUZZER: Fuzzer> FuzzVm<'a, FUZZER> {
let curr_byte = self.read::<u8>(bp_addr, cr3)?;
if curr_byte != 0xcc {
// Store the original byte for this address
hit_breakpoints.insert(bp_addr.into(), curr_byte);
hit_breakpoints.insert(bp_addr, curr_byte);

// Write a breakpoint at this address to look for coverage
self.write_bytes_dirty(bp_addr, cr3, &[0xcc])?;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ fn handle_vmexit<FUZZER: Fuzzer>(
};

if let Some(crash_file) =
write_crash_input(&crash_dir, &dirname, &input, &fuzzvm.console_output)?
write_crash_input(&crash_dir, &dirname, input, &fuzzvm.console_output)?
{
// Allow the fuzzer to handle the crashing state
// Useful for things like syscall fuzzer to write a C file from the input
Expand Down
10 changes: 5 additions & 5 deletions src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Memory {
libc::madvise(mem_ptr, guest_memory_size as usize, libc::MADV_MERGEABLE);
}

Ok(Memory::from_addr(mem_ptr as u64, guest_memory_size as u64))
Ok(Memory::from_addr(mem_ptr as u64, guest_memory_size))
}

/// Get the underlying backing address
Expand Down Expand Up @@ -435,7 +435,7 @@ impl Memory {
// [Lvl1index][Lvl2index][Lvl3index][Lvl4index]
let mut table_indexes = virt_addr.table_indexes();

for (_level, index) in table_indexes.iter_mut().enumerate() {
for index in table_indexes.iter_mut() {
// Get the page table entry at the given index
let entry = &mut curr_table[*index];

Expand Down Expand Up @@ -527,7 +527,7 @@ impl Memory {
pub fn read_phys_bytes<T: Copy>(&mut self, phys_addr: PhysAddr, buf: &mut [T]) -> Result<()> {
if let Some(last_addr) = phys_addr.0.checked_add(buf.len() as u64) {
ensure!(
last_addr <= self.memory_backing + self.size as u64,
last_addr <= self.memory_backing + self.size,
Error::ReadPhysicalAddressOutOfBounds
);

Expand Down Expand Up @@ -572,7 +572,7 @@ impl Memory {

if let Some(last_addr) = phys_addr.0.checked_add(std::mem::size_of::<T>() as u64) {
ensure!(
last_addr <= self.memory_backing + self.size as u64,
last_addr <= self.memory_backing + self.size,
Error::ReadPhysicalAddressOutOfBounds
);

Expand Down Expand Up @@ -615,7 +615,7 @@ impl Memory {
.context(Error::ReadFromUnmappedVirtualAddress(virt_addr, cr3))?;

// Read the requested type from the translated physical address
Ok(self.read_phys(phys_addr)?)
self.read_phys(phys_addr)
}

/// Read the requested type from the given [`VirtAddr`] using the [`Cr3`] page table
Expand Down
2 changes: 1 addition & 1 deletion src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Descriptor {
base: self.base.unwrap(),
limit: self.limit,
selector: self.selector,
type_: type_,
type_,
present: self.present.into(),
dpl: self.descriptor_privilege as u8,
db: 0,
Expand Down
10 changes: 5 additions & 5 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ pub fn worker<FUZZER: Fuzzer>(
alive = 0;

// Calculate the current statistics
for (_core_id, core_stats) in stats.iter().enumerate() {
for core_stats in stats.iter() {
let mut stats = core_stats.lock().unwrap();

// Add this core's corpus to the total corpus
Expand Down Expand Up @@ -2199,10 +2199,10 @@ impl DebugInfo {
}

/// populate debug info given a project state and associated addr2line contexts.
pub fn populate<'a>(
pub fn populate(
&mut self,
project_state: &crate::ProjectState,
contexts: &'a ContextSlice,
contexts: &ContextSlice,
) -> Result<()> {
let cov_bps = project_state
.coverage_basic_blocks
Expand Down Expand Up @@ -2246,7 +2246,7 @@ impl DebugInfo {
.modules
.get_module_start_containing(start_addr)
{
start_addr = start_addr - module_start;
start_addr -= module_start;
} else {
break;
}
Expand Down Expand Up @@ -2348,7 +2348,7 @@ impl DebugInfo {
}

/// Obtain the first debug location associated with the given address.
pub fn get_first_location<'a, V: Into<VirtAddr>>(&'a self, addr: V) -> Option<(&'a str, u32)> {
pub fn get_first_location<V: Into<VirtAddr>>(&self, addr: V) -> Option<(&str, u32)> {
let addr: VirtAddr = addr.into();
if let Some(locs) = self.vaddrs.get(&addr) {
if let Some(loc_index) = locs.first().copied() {
Expand Down
Loading

0 comments on commit b17ab00

Please sign in to comment.