Skip to content

Commit cff29c5

Browse files
committed
Clippy, ensuring C++ runtime in debug builds, required ny libafl_frida, unti fixed
1 parent e3b3ac0 commit cff29c5

File tree

5 files changed

+50
-58
lines changed

5 files changed

+50
-58
lines changed

fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ pub fn main() {
1818

1919
let mut cc = ClangWrapper::new();
2020
if let Some(code) = cc
21-
.cpp(is_cpp)
22-
// silence the compiler wrapper output, needed for some configure scripts.
21+
.cpp(true) // Link with C++ standard library (Frida links to it in order to hook C++ functions)
22+
// .cpp(is_cpp)
23+
// silence the compiler wrapper output, needed for some configure scripts.
2324
.silence(true)
2425
.parse_args(&args)
2526
.expect("Failed to parse the command line")

fuzzers/libfuzzer_libpng/src/lib.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,6 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
9191
.track_indices()
9292
};
9393

94-
let options = FuzzerOptions::try_parse();
95-
log::info!("Options: {:?}", options );
96-
let save_bb_coverage = options
97-
.as_ref()
98-
.map(|opts| opts.save_bb_coverage)
99-
.unwrap_or(false);
100-
let drcov_max_execution_cnt = options
101-
.as_ref()
102-
.map(|opts| opts.drcov_max_execution_cnt)
103-
.unwrap_or(0);
104-
let acc_observer = unsafe {
105-
AccMapObserver::new(StdMapObserver::from_mut_ptr(
106-
"edges",
107-
EDGES_MAP.as_mut_ptr(),
108-
MAX_EDGES_FOUND,
109-
))
110-
.save_dr_cov(save_bb_coverage)
111-
.max_cnt(drcov_max_execution_cnt)
112-
};
113-
11494
let options = FuzzerOptions::try_parse();
11595
let save_bb_coverage = options
11696
.as_ref()

fuzzers/toolbox/src/accum_observer.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs;
44
use std::{
55
collections::HashMap,
66
hash::{BuildHasher, Hash, Hasher},
7+
num::ParseIntError,
78
path::PathBuf,
89
};
910

@@ -128,18 +129,18 @@ where
128129
if self.acc[i] == 0 {
129130
continue;
130131
}
131-
if pc_table.is_none() {
132+
if let Some(pc_table) = pc_table {
133+
// The addresses from PCTable are real memory addresses
134+
// The module is mapped starting from the beginning of the .init section
132135
drcov_basic_blocks.push(DrCovBasicBlock {
133-
// I need the address to point to real memory addresses
134-
start: self.curr_mod_addr + i as usize, // this is fixed in the script
135-
end: self.curr_mod_addr + i as usize, // this is fixed in the script start == end indicates to fix the start as well
136+
start: pc_table[i].addr() + self.curr_mod_offset,
137+
end: pc_table[i].addr() + self.curr_mod_offset + 1, // this is fixed in the script
136138
});
137139
} else {
138-
// The addresses from PCTable are real memory addresses
139-
// The module is mapped starting from the beginning of the .init section
140140
drcov_basic_blocks.push(DrCovBasicBlock {
141-
start: pc_table.unwrap()[i].addr() + self.curr_mod_offset,
142-
end: pc_table.unwrap()[i].addr() + self.curr_mod_offset + 1, // this is fixed in the script
141+
// I need the address to point to real memory addresses
142+
start: self.curr_mod_addr + i, // this is fixed in the script
143+
end: self.curr_mod_addr + i, // this is fixed in the script start == end indicates to fix the start as well
143144
});
144145
}
145146

@@ -281,9 +282,19 @@ fn get_pid_name(pid: Option<u32>) -> String {
281282
}
282283
}
283284

285+
#[derive(Debug)]
286+
pub enum CollectModulesError {
287+
IoError(std::io::Error),
288+
ParseError(std::num::ParseIntError),
289+
}
290+
impl From<ParseIntError> for CollectModulesError {
291+
fn from(err: ParseIntError) -> Self {
292+
CollectModulesError::ParseError(err)
293+
}
294+
}
284295
/// A utility function to collect the modules of the current process and their ranges in memory
285296
#[allow(unused_mut)]
286-
pub fn collect_modules(pid: Option<u32>) -> Result<RangeMap<usize, (u16, String)>, ()> {
297+
pub fn collect_modules(pid: Option<u32>) -> Result<RangeMap<usize, (u16, String)>, CollectModulesError> {
287298
let mut ranges = RangeMap::new();
288299
#[cfg(windows)]
289300
{
@@ -300,15 +311,15 @@ pub fn collect_modules(pid: Option<u32>) -> Result<RangeMap<usize, (u16, String)
300311
};
301312

302313
let file = File::open(get_pid_name(pid));
303-
if file.is_err() {
304-
return Err(());
314+
if let Err(file_err) = file {
315+
return Err(CollectModulesError::IoError(file_err));
305316
}
306317
let reader = BufReader::new(file.unwrap());
307318
let mut module_id = 0;
308319

309320
for line in reader.lines() {
310321
if line.is_err() {
311-
continue;
322+
continue
312323
}
313324
let line = line.unwrap();
314325
log::info!("Line: {}", line);
@@ -327,8 +338,8 @@ pub fn collect_modules(pid: Option<u32>) -> Result<RangeMap<usize, (u16, String)
327338
if !parts[1].contains('x') {
328339
continue;
329340
}
330-
let start = usize::from_str_radix(range_parts[0], 16).map_err(|_| ())?;
331-
let end = usize::from_str_radix(range_parts[1], 16).map_err(|_| ())?;
341+
let start = usize::from_str_radix(range_parts[0], 16)?;
342+
let end = usize::from_str_radix(range_parts[1], 16)?;
332343
let name = parts[5].to_string();
333344

334345
log::info!("Module: {} - 0x{:x} - 0x{:x}", name, start, end);
@@ -397,7 +408,7 @@ fn collect_module_offsets(pid: Option<u32>) -> Result<HashMap<String, usize>, ()
397408
// Iterate over section headers to find the .init section
398409
for sh in elf.section_headers {
399410
let offset = sh.sh_offset as usize;
400-
if let Some(section_name) = elf.shdr_strtab.get_at(sh.sh_name as usize) {
411+
if let Some(section_name) = elf.shdr_strtab.get_at(sh.sh_name) {
401412
if section_name == ".init" {
402413
log::info!(
403414
"Module: {} - 0x{:x} - 0x{:x}",
@@ -440,7 +451,7 @@ fn find_module_params(
440451
// curr_mod_name = ranges.get(&0).unwrap().1.clone();
441452
for (_, val) in ranges.iter() {
442453
if val.0 == curr_mod_id {
443-
curr_mod_name = val.1.clone();
454+
curr_mod_name.clone_from(&val.1);
444455
break;
445456
}
446457
}
@@ -487,9 +498,9 @@ where
487498
cnt: 0,
488499
max_cnt: 0,
489500
stored_cnt: 0,
490-
ranges: ranges,
491-
curr_mod_offset: curr_mod_offset.clone(),
492-
curr_mod_addr: curr_mod_addr,
501+
ranges,
502+
curr_mod_offset,
503+
curr_mod_addr,
493504
use_pc_table: false,
494505
target_pid: 0,
495506
}

fuzzers/toolbox/src/crash_stack.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ impl<'de> Visitor<'de> for PPFrameVisitor {
106106
"ip" => {
107107
let ip_str: String = map.next_value()?;
108108
ip = Some(
109-
usize::from_str_radix(&ip_str.trim_start_matches("0x"), 16)
109+
usize::from_str_radix(ip_str.trim_start_matches("0x"), 16)
110110
.map_err(de::Error::custom)?,
111111
);
112112
}
113113
"symbol_address" => {
114114
let symbol_address_str: String = map.next_value()?;
115115
symbol_address = Some(
116-
usize::from_str_radix(&symbol_address_str.trim_start_matches("0x"), 16)
116+
usize::from_str_radix(symbol_address_str.trim_start_matches("0x"), 16)
117117
.map_err(de::Error::custom)?,
118118
);
119119
}
@@ -122,7 +122,7 @@ impl<'de> Visitor<'de> for PPFrameVisitor {
122122
if module_base_address_str != "unknown" {
123123
module_base_address = Some(
124124
usize::from_str_radix(
125-
&module_base_address_str.trim_start_matches("0x"),
125+
module_base_address_str.trim_start_matches("0x"),
126126
16,
127127
)
128128
.map_err(de::Error::custom)?,
@@ -157,20 +157,20 @@ impl<'de> Visitor<'de> for PPFrameVisitor {
157157
let ip_str = seq
158158
.next_element::<String>()?
159159
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
160-
let ip = usize::from_str_radix(&ip_str.trim_start_matches("0x"), 16)
160+
let ip = usize::from_str_radix(ip_str.trim_start_matches("0x"), 16)
161161
.map_err(de::Error::custom)?;
162162

163163
let symbol_address_str = seq
164164
.next_element::<String>()?
165165
.ok_or_else(|| de::Error::invalid_length(1, &self))?;
166166
let symbol_address =
167-
usize::from_str_radix(&symbol_address_str.trim_start_matches("0x"), 16)
167+
usize::from_str_radix(symbol_address_str.trim_start_matches("0x"), 16)
168168
.map_err(de::Error::custom)?;
169169

170170
let module_base_address_str = seq.next_element::<String>()?;
171171
let module_base_address_str = match module_base_address_str {
172172
Some(s) if s != "unknown" => Some(
173-
usize::from_str_radix(&s.trim_start_matches("0x"), 16)
173+
usize::from_str_radix(s.trim_start_matches("0x"), 16)
174174
.map_err(de::Error::custom)?,
175175
),
176176
_ => None,
@@ -183,7 +183,7 @@ impl<'de> Visitor<'de> for PPFrameVisitor {
183183
ip,
184184
symbol_address,
185185
module_base_address: module_base_address_str,
186-
symbols: symbols,
186+
symbols,
187187
})
188188
}
189189
}
@@ -215,7 +215,7 @@ impl Serialize for BacktraceMetadata {
215215
module_base_address: frame.module_base_address().map(|addr| addr as usize),
216216
symbols: frame
217217
.symbols()
218-
.get(0)
218+
.first()
219219
.map(|symbol| format!("{:?}", symbol))
220220
.unwrap_or_else(|| "No symbol".to_string()),
221221
};
@@ -247,8 +247,8 @@ impl<'de> Visitor<'de> for BacktraceMetadataVisitor {
247247
// Read all elements from the sequence
248248
// while let Some(_) = seq.next_element::<HashMap<String, Self::Value>>()? {}
249249
// Read the name string and discard it
250-
let _ = seq.next_element::<String>().map_err(|err| err);
251-
while let Some(_) = seq.next_element::<PPFrame>().map_err(|err| err)? {}
250+
let _ = seq.next_element::<String>();
251+
while (seq.next_element::<PPFrame>()?).is_some() {}
252252
// Always return a current BacktraceMetadata.
253253
Ok(BacktraceMetadata::new(Backtrace::new_unresolved()))
254254
}
@@ -423,7 +423,7 @@ where
423423
// .match_name::<BacktraceObserverWithStack>(&self.0.observer_name())
424424
// .expect("A NewHashFeedbackWithStack needs a BacktraceObserverWithStack");
425425
let observer = observers
426-
.get(&self.0.observer_handle())
426+
.get(self.0.observer_handle())
427427
.expect("A NewHashFeedbackWithStack needs a BacktraceObserverWithStack");
428428

429429
match observer.get_backtrace() {

fuzzers/toolbox/src/reachability_rt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl ReachabilityRuntime {
118118
hooks_cnt: 0,
119119
hook_indices: HashMap::new(),
120120
_pinned: PhantomPinned,
121-
hooks: hooks,
121+
hooks,
122122
})),
123123
}
124124
}
@@ -188,15 +188,15 @@ impl ReachabilityRuntime {
188188
.insert(name.to_string(), hook_idx);
189189
let hook_ctx = HookCtx {
190190
rt: self,
191-
org_fn: frida_gum::Module::find_export_by_name(Some(&lib), &name)
191+
org_fn: frida_gum::Module::find_export_by_name(Some(lib), name)
192192
.expect("Failed to find function"),
193-
hook_idx: hook_idx,
193+
hook_idx,
194194
};
195195
let hook_ctx_ptr = Box::into_raw(Box::new(hook_ctx));
196196

197197
interceptor
198198
.replace(
199-
frida_gum::Module::find_export_by_name(Some(&lib), &name)
199+
frida_gum::Module::find_export_by_name(Some(lib), name)
200200
.expect("Failed to find function"),
201201
NativePointer(replacement as *mut c_void),
202202
NativePointer(hook_ctx_ptr as *mut c_void),
@@ -233,7 +233,6 @@ impl ReachabilityRuntime {
233233
),
234234
_ => {
235235
log::error!("Unsupported number of parameters for function {}", name);
236-
return;
237236
}
238237
}
239238
}
@@ -292,6 +291,7 @@ pub struct ReachabilityObserver {
292291
impl ReachabilityObserver {
293292
/// Creates a new [`ReachabilityObserver`] with the given name.
294293
#[must_use]
294+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
295295
pub fn new<S>(observer_name: S, map: *mut u8, hooks_file: Option<&str>) -> Self
296296
where
297297
S: Into<Cow<'static, str>> + Clone,
@@ -316,7 +316,7 @@ impl ReachabilityObserver {
316316
Self {
317317
observer_name: observer_name.clone().into(),
318318
base: unsafe { StdMapObserver::from_mut_ptr(observer_name, map, MAP_SIZE) },
319-
hooks: hooks,
319+
hooks,
320320
invocations: Vec::new(),
321321
}
322322
}

0 commit comments

Comments
 (0)