Skip to content

Commit 6cc1e96

Browse files
committed
clippy fixes
1 parent 0ac407a commit 6cc1e96

File tree

9 files changed

+60
-54
lines changed

9 files changed

+60
-54
lines changed

fuzzers/libfuzzer_libpng/Makefile

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
11
PWD=`pwd`
2+
FUZZER_NAME="fuzzer_libpng"
23

34
all:
45
# Build the libpng libfuzzer library
56
cargo build --release
67

78
# Build the libpng harness
8-
$(PWD)/target/release/cxx \
9+
$(PWD)/target/release/libafl_cxx \
910
$(PWD)/harness.cc \
1011
$(PWD)/libpng-1.6.37/.libs/libpng16.a \
1112
-I$(PWD)/libpng-1.6.37/ \
12-
-o fuzzer \
13+
-o $(FUZZER_NAME) \
1314
-lm -lz
1415

1516
run: all
16-
./fuzzer &
17-
./fuzzer >/dev/null 2>/dev/null &
17+
./$(FUZZER_NAME) &
18+
sleep 0.2
19+
./$(FUZZER_NAME) >/dev/null 2>/dev/null &
1820

1921
test: all
20-
timeout 60s ./fuzzer &
21-
timeout 59s taskset 0x00000001 ./fuzzer >/dev/null 2>/dev/null &
22-
timeout 59s taskset 0x00000002 ./fuzzer >/dev/null 2>/dev/null &
23-
timeout 59s taskset 0x00000004 ./fuzzer >/dev/null 2>/dev/null &
24-
timeout 59s taskset 0x00000008 ./fuzzer >/dev/null 2>/dev/null &
25-
# timeout 59s taskset 0x00000010 ./fuzzer >/dev/null 2>/dev/null &
26-
# timeout 59s taskset 0x00000020 ./fuzzer >/dev/null 2>/dev/null &
27-
# timeout 59s taskset 0x00000040 ./fuzzer >/dev/null 2>/dev/null &
28-
# timeout 59s taskset 0x00000080 ./fuzzer >/dev/null 2>/dev/null &
29-
# timeout 59s taskset 0x00000100 ./fuzzer >/dev/null 2>/dev/null &
30-
# timeout 59s taskset 0x00000200 ./fuzzer >/dev/null 2>/dev/null &
31-
# timeout 59s taskset 0x00000400 ./fuzzer >/dev/null 2>/dev/null &
32-
# timeout 59s taskset 0x00000800 ./fuzzer >/dev/null 2>/dev/null &
33-
# timeout 59s taskset 0x00001000 ./fuzzer >/dev/null 2>/dev/null &
34-
# timeout 59s taskset 0x00002000 ./fuzzer >/dev/null 2>/dev/null &
35-
# timeout 59s taskset 0x00004000 ./fuzzer >/dev/null 2>/dev/null &
36-
# timeout 59s taskset 0x00008000 ./fuzzer >/dev/null 2>/dev/null &
37-
# timeout 59s taskset 0x00010000 ./fuzzer >/dev/null 2>/dev/null &
38-
# timeout 59s taskset 0x00020000 ./fuzzer >/dev/null 2>/dev/null &
39-
# timeout 59s taskset 0x00040000 ./fuzzer >/dev/null 2>/dev/null &
40-
# timeout 59s taskset 0x00080000 ./fuzzer >/dev/null 2>/dev/null &
41-
# timeout 59s taskset 0x00100000 ./fuzzer >/dev/null 2>/dev/null &
42-
# timeout 59s taskset 0x00200000 ./fuzzer >/dev/null 2>/dev/null &
43-
# timeout 59s taskset 0x00400000 ./fuzzer >/dev/null 2>/dev/null &
44-
# timeout 59s taskset 0x00800000 ./fuzzer >/dev/null 2>/dev/null &
45-
# timeout 59s taskset 0x01000000 ./fuzzer >/dev/null 2>/dev/null &
46-
# timeout 59s taskset 0x02000000 ./fuzzer >/dev/null 2>/dev/null &
47-
# timeout 59s taskset 0x04000000 ./fuzzer >/dev/null 2>/dev/null &
48-
# timeout 59s taskset 0x08000000 ./fuzzer >/dev/null 2>/dev/null &
49-
# timeout 59s taskset 0x10000000 ./fuzzer >/dev/null 2>/dev/null &
50-
# timeout 59s taskset 0x20000000 ./fuzzer >/dev/null 2>/dev/null &
51-
# timeout 59s taskset 0x40000000 ./fuzzer >/dev/null 2>/dev/null &
52-
# timeout 59s taskset 0x80000000 ./fuzzer >/dev/null 2>/dev/null &
22+
timeout 60s ./$(FUZZER_NAME) &
23+
sleep 0.2
24+
timeout 59s taskset 0x00000001 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
25+
timeout 59s taskset 0x00000002 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
26+
timeout 59s taskset 0x00000004 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
27+
timeout 59s taskset 0x00000008 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
28+
# timeout 59s taskset 0x00000010 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
29+
# timeout 59s taskset 0x00000020 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
30+
# timeout 59s taskset 0x00000040 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
31+
# timeout 59s taskset 0x00000080 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
32+
# timeout 59s taskset 0x00000100 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
33+
# timeout 59s taskset 0x00000200 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
34+
# timeout 59s taskset 0x00000400 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
35+
# timeout 59s taskset 0x00000800 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
36+
# timeout 59s taskset 0x00001000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
37+
# timeout 59s taskset 0x00002000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
38+
# timeout 59s taskset 0x00004000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
39+
# timeout 59s taskset 0x00008000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
40+
# timeout 59s taskset 0x00010000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
41+
# timeout 59s taskset 0x00020000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
42+
# timeout 59s taskset 0x00040000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
43+
# timeout 59s taskset 0x00080000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
44+
# timeout 59s taskset 0x00100000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
45+
# timeout 59s taskset 0x00200000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
46+
# timeout 59s taskset 0x00400000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
47+
# timeout 59s taskset 0x00800000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
48+
# timeout 59s taskset 0x01000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
49+
# timeout 59s taskset 0x02000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
50+
# timeout 59s taskset 0x04000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
51+
# timeout 59s taskset 0x08000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
52+
# timeout 59s taskset 0x10000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
53+
# timeout 59s taskset 0x20000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
54+
# timeout 59s taskset 0x40000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &
55+
# timeout 59s taskset 0x80000000 ./$(FUZZER_NAME) >/dev/null 2>/dev/null &

fuzzers/libfuzzer_libpng/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ In contrast to other fuzzer examples, this setup uses `fuzz_loop_for`, to occasi
66
While this costs performance, it can be useful for targets with memory leaks or other instabilities.
77
If your target is really instable, however, consider exchanging the `InProcessExecutor` for a `ForkserverExecutor` instead.
88

9+
It also uses the `introspection` feature, printing fuzzer stats during execution.
10+
911
To show off crash detection, we added a `ud2` instruction to the harness, edit harness.cc if you want a non-crashing example.
1012
It has been tested on Linux.
1113

@@ -51,7 +53,7 @@ This allows you to run multiple different builds of the same fuzzer alongside, f
5153

5254
## Run
5355

54-
The first time you run the binary, the broker will open a tcp port (currently on port `1337`), waiting for fuzzer clients to connect. This port is local and only used for the initial handshake. All further communication happens via shared map, to be independent of the kernel. Currently you must run the clients from the libfuzzer_libpng directory for them to be able to access the PNG corpus.
56+
The first time you run the binary, the broker will open a tcp port (currently on port `1337`), waiting for fuzzer clients to connect. This port is local and only used for the initial handshake. All further communication happens via shared map, to be independent of the kernel. Currently, you must run the clients from the libfuzzer_libpng directory for them to be able to access the PNG corpus.
5557

5658
```
5759
./fuzzer_libpng

fuzzers/libfuzzer_libpng/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn fuzz(corpus_dirs: Vec<PathBuf>, objective_dir: PathBuf, broker_port: u16) ->
6363
}
6464
},
6565
};
66-
66+
6767
// Create an observation channel using the coverage map
6868
let edges = unsafe { &mut EDGES_MAP[0..MAX_EDGES_NUM] };
6969
let edges_observer = HitcountsMapObserver::new(StdMapObserver::new("edges", edges));
@@ -78,7 +78,6 @@ fn fuzz(corpus_dirs: Vec<PathBuf>, objective_dir: PathBuf, broker_port: u16) ->
7878
StdRand::with_seed(current_nanos()),
7979
// Corpus that will be evolved, we keep it in memory for performance
8080
InMemoryCorpus::new(),
81-
8281
// Feedbacks to rate the interestingness of an input
8382
feedback_or!(
8483
MaxMapFeedback::new_tracking_with_observer(&edges_observer, true, false),
@@ -92,7 +91,6 @@ fn fuzz(corpus_dirs: Vec<PathBuf>, objective_dir: PathBuf, broker_port: u16) ->
9291
)
9392
});
9493

95-
9694
println!("We're a client, let's fuzz :)");
9795

9896
// Create a PNG dictionary if not existing

libafl/src/cpu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/// implementations of reading a cycle counter. In this way, an experiment only has to
77
/// change this implementation rather than every instead of [`cpu::read_time_counter`]
88
#[cfg(target_arch = "x86_64")]
9+
#[must_use]
910
pub fn read_time_counter() -> u64 {
1011
unsafe { core::arch::x86_64::_rdtsc() }
1112
}

libafl/src/events/llmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ where
262262
client.update_executions(*executions as u64, *time);
263263

264264
// Update the performance stats for this client
265-
client.update_introspection_stats(*introspection_stats);
265+
client.update_introspection_stats(**introspection_stats);
266266

267267
// Display the stats via `.display` only on core #1
268268
if sender_id == 1 {

libafl/src/events/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ where
111111
executions: usize,
112112

113113
/// Current performance statistics
114-
introspection_stats: ClientPerfStats,
114+
introspection_stats: Box<ClientPerfStats>,
115115

116116
phantom: PhantomData<I>,
117117
},

libafl/src/events/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
} => {
116116
// TODO: The stats buffer should be added on client add.
117117
stats.client_stats_mut()[0].update_executions(*executions as u64, *time);
118-
stats.client_stats_mut()[0].update_introspection_stats(*introspection_stats);
118+
stats.client_stats_mut()[0].update_introspection_stats(**introspection_stats);
119119
stats.display(event.name().to_string());
120120
Ok(BrokerEventResult::Handled)
121121
}

libafl/src/fuzzer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ pub trait Fuzzer<E, EM, S, CS> {
120120
Ok(ret)
121121
}
122122

123-
/// Given the last time, if stats_timeout seconds passed, send off an info/stats/heartbeat message to the broker.
123+
/// Given the last time, if `stats_timeout` seconds passed, send off an info/stats/heartbeat message to the broker.
124124
/// Returns the new `last` time (so the old one, unless `stats_timeout` time has passed and stats have been sent)
125-
/// Will return an Error, if the stats could not be sent.
125+
/// Will return an [`crate::Error`], if the stats could not be sent.
126126
fn maybe_report_stats(
127127
state: &mut S,
128128
manager: &mut EM,
@@ -225,7 +225,7 @@ where
225225
Event::UpdatePerfStats {
226226
executions: *state.executions(),
227227
time: cur,
228-
introspection_stats: state.introspection_stats().clone(),
228+
introspection_stats: Box::new(*state.introspection_stats()),
229229
phantom: PhantomData,
230230
},
231231
)?;

libafl/src/stats/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,12 @@ const NUM_PERF_FEATURES: usize = PerfFeature::Count as usize;
396396
impl ClientPerfStats {
397397
/// Create a blank [`ClientPerfStats`] with the `start_time` and `current_time` with
398398
/// the current clock counter
399+
#[must_use]
399400
pub fn new() -> Self {
400-
let start_time = crate::cpu::read_time_counter().try_into().unwrap();
401+
let start_time = crate::cpu::read_time_counter();
401402

402403
Self {
403-
start_time: start_time,
404+
start_time,
404405
current_time: start_time,
405406
scheduler: 0,
406407
manager: 0,
@@ -604,6 +605,7 @@ impl ClientPerfStats {
604605

605606
#[cfg(feature = "introspection")]
606607
impl core::fmt::Display for ClientPerfStats {
608+
#[allow(clippy::cast_precision_loss)]
607609
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
608610
// Calculate the elapsed time from the stats
609611
let elapsed: f64 = (self.current_time - self.start_time) as f64;
@@ -620,7 +622,7 @@ impl core::fmt::Display for ClientPerfStats {
620622
// Create the formatted string
621623
writeln!(
622624
f,
623-
"Scheduler: {:4.2} | Manager: {:4.2} | Stages:\n",
625+
"Scheduler: {:4.2} | Manager: {:4.2} | Stages:",
624626
scheduler_percent, manager_percent
625627
)?;
626628

@@ -632,7 +634,7 @@ impl core::fmt::Display for ClientPerfStats {
632634
}
633635

634636
// Write the stage header
635-
write!(f, " Stage {}:\n", stage_index)?;
637+
writeln!(f, " Stage {}:", stage_index)?;
636638

637639
for (feature_index, feature) in features.iter().enumerate() {
638640
// Calculate this current stage's percentage
@@ -650,7 +652,7 @@ impl core::fmt::Display for ClientPerfStats {
650652
let feature: PerfFeature = feature_index.into();
651653

652654
// Write the percentage for this feature
653-
write!(f, " {:6.4}: {:?}\n", feature_percent, feature)?;
655+
writeln!(f, " {:6.4}: {:?}", feature_percent, feature)?;
654656
}
655657

656658
for (feedback_index, feedback) in self.feedbacks.iter().enumerate() {
@@ -666,9 +668,9 @@ impl core::fmt::Display for ClientPerfStats {
666668
other_percent -= feedback_percent;
667669

668670
// Write the percentage for this feedback
669-
write!(
671+
writeln!(
670672
f,
671-
" {:6.4}: Feedback index {}\n",
673+
" {:6.4}: Feedback index {}",
672674
feedback_percent, feedback_index
673675
)?;
674676
}

0 commit comments

Comments
 (0)