Skip to content

Commit c24c449

Browse files
Merge pull request #56 from teymour-aldridge/2024
2024
2 parents ebe8182 + 55ee8fb commit c24c449

File tree

18 files changed

+88
-90
lines changed

18 files changed

+88
-90
lines changed

cargo-fuzzcheck/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "cargo-fuzzcheck"
33
version = "0.13.0"
44
authors = ["Loïc Lecrenier <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66
description = "Command line tool to use fuzzcheck-rs"
77
homepage = "https://fuzzcheck.neocities.org"
88
repository = "https://github.com/loiclec/fuzzcheck-rs"
@@ -20,4 +20,4 @@ version = "0.13"
2020

2121
[[bin]]
2222
name = "cargo-fuzzcheck"
23-
path = "src/main.rs"
23+
path = "src/main.rs"

fuzzcheck/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "fuzzcheck"
33
version = "0.13.0"
44
authors = ["Loïc Lecrenier <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66
description = "A modular, structure-aware, and feedback-driven fuzzing engine for Rust functions"
77
homepage = "https://fuzzcheck.neocities.org"
88
repository = "https://github.com/loiclec/fuzzcheck-rs"

fuzzcheck/src/bitset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl FixedBitSet {
199199
/// Iterator element is the index of the `1` bit, type `usize`.
200200
#[inline]
201201
#[coverage(off)]
202-
pub fn ones(&self) -> Ones {
202+
pub fn ones(&self) -> Ones<'_> {
203203
match self.as_slice().split_first() {
204204
Some((&block, rem)) => Ones {
205205
bitset: block,

fuzzcheck/src/builder.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ use std::result::Result;
6565
use std::time::Duration;
6666

6767
use fuzzcheck_common::arg::{
68-
options_parser, Arguments, ArgumentsError, FuzzerCommand, COMMAND_FUZZ, COMMAND_MINIFY_INPUT, INPUT_FILE_FLAG,
68+
Arguments, ArgumentsError, COMMAND_FUZZ, COMMAND_MINIFY_INPUT, FuzzerCommand, INPUT_FILE_FLAG, options_parser,
6969
};
7070

71+
#[cfg(feature = "serde_ron_serializer")]
72+
use crate::SerdeRonSerializer;
73+
#[cfg(feature = "serde_json_serializer")]
74+
use crate::SerdeSerializer;
7175
use crate::code_coverage_sensor::CodeCoverageSensor;
7276
use crate::fuzzer::{Fuzzer, FuzzingResult};
7377
use crate::sensors_and_pools::{
7478
AndPool, DifferentObservations, MaximiseEachCounterPool, MaximiseObservationPool, MostNDiversePool,
7579
SameObservations, SimplestToActivateCounterPool, WrapperSensor,
7680
};
77-
#[cfg(feature = "serde_ron_serializer")]
78-
use crate::SerdeRonSerializer;
79-
#[cfg(feature = "serde_json_serializer")]
80-
use crate::SerdeSerializer;
8181
use crate::{
82-
split_string_by_whitespace, CompatibleWithObservations, DefaultMutator, Mutator, PoolExt, Sensor, SensorExt,
83-
Serializer,
82+
CompatibleWithObservations, DefaultMutator, Mutator, PoolExt, Sensor, SensorExt, Serializer,
83+
split_string_by_whitespace,
8484
};
8585

8686
/** A function that can be fuzz-tested.
@@ -693,18 +693,9 @@ where
693693
}
694694

695695
pub type BasicSensor = CodeCoverageSensor;
696-
pub type DiverseSensor = impl WrapperSensor<
697-
Wrapped = CodeCoverageSensor,
698-
Observations = (<CodeCoverageSensor as Sensor>::Observations, usize),
699-
>;
700-
pub type MaxHitsSensor = impl WrapperSensor<
701-
Wrapped = CodeCoverageSensor,
702-
Observations = (<CodeCoverageSensor as Sensor>::Observations, u64),
703-
>;
704-
pub type BasicAndMaxHitsSensor = impl WrapperSensor<
705-
Wrapped = CodeCoverageSensor,
706-
Observations = (<CodeCoverageSensor as Sensor>::Observations, u64),
707-
>;
696+
pub type DiverseSensor = impl WrapperSensor<Wrapped = CodeCoverageSensor, Observations = (<CodeCoverageSensor as Sensor>::Observations, usize)>;
697+
pub type MaxHitsSensor = impl WrapperSensor<Wrapped = CodeCoverageSensor, Observations = (<CodeCoverageSensor as Sensor>::Observations, u64)>;
698+
pub type BasicAndMaxHitsSensor = impl WrapperSensor<Wrapped = CodeCoverageSensor, Observations = (<CodeCoverageSensor as Sensor>::Observations, u64)>;
708699

709700
pub type BasicPool = SimplestToActivateCounterPool;
710701
pub type DiversePool = AndPool<MostNDiversePool, MaximiseObservationPool<u64>, DifferentObservations>;
@@ -919,9 +910,9 @@ impl SensorAndPoolBuilder<BasicSensor, BasicPool> {
919910
impl<T> SensorAndPoolBuilder<T, BasicAndDiversePool>
920911
where
921912
T: WrapperSensor<
922-
Wrapped = CodeCoverageSensor,
923-
Observations = (<CodeCoverageSensor as Sensor>::Observations, usize),
924-
>,
913+
Wrapped = CodeCoverageSensor,
914+
Observations = (<CodeCoverageSensor as Sensor>::Observations, usize),
915+
>,
925916
{
926917
/// Augment the current pool such that it also tries to find test cases repeatedly hitting the same regions of code.
927918
#[coverage(off)]

fuzzcheck/src/code_coverage_sensor/llvm_coverage.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::leb128;
99

1010
type CovMap = HashMap<[u8; 8], Vec<String>>;
1111

12-
extern "C" {
12+
unsafe extern "C" {
1313
pub(crate) fn get_start_instrumentation_counters() -> *mut u64;
1414
pub(crate) fn get_end_instrumentation_counters() -> *mut u64;
1515
pub(crate) fn get_start_prf_data() -> *const u8;
@@ -20,24 +20,30 @@ extern "C" {
2020

2121
#[coverage(off)]
2222
pub unsafe fn get_counters() -> &'static mut [u64] {
23-
let start = get_start_instrumentation_counters();
24-
let end = get_end_instrumentation_counters();
25-
let len = end.offset_from(start) as usize;
26-
std::slice::from_raw_parts_mut(start, len)
23+
unsafe {
24+
let start = get_start_instrumentation_counters();
25+
let end = get_end_instrumentation_counters();
26+
let len = end.offset_from(start) as usize;
27+
std::slice::from_raw_parts_mut(start, len)
28+
}
2729
}
2830
#[coverage(off)]
2931
pub unsafe fn get_prf_data() -> &'static [u8] {
30-
let start = get_start_prf_data();
31-
let end = get_end_prf_data();
32-
let len = end.offset_from(start) as usize;
33-
std::slice::from_raw_parts(start, len)
32+
unsafe {
33+
let start = get_start_prf_data();
34+
let end = get_end_prf_data();
35+
let len = end.offset_from(start) as usize;
36+
std::slice::from_raw_parts(start, len)
37+
}
3438
}
3539
#[coverage(off)]
3640
pub unsafe fn get_prf_names() -> &'static [u8] {
37-
let start = get_start_prf_names();
38-
let end = get_end_prf_names();
39-
let len = end.offset_from(start) as usize;
40-
std::slice::from_raw_parts(start, len)
41+
unsafe {
42+
let start = get_start_prf_names();
43+
let end = get_end_prf_names();
44+
let len = end.offset_from(start) as usize;
45+
std::slice::from_raw_parts(start, len)
46+
}
4147
}
4248

4349
pub struct LLVMCovSections {

fuzzcheck/src/code_coverage_sensor/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::collections::{BTreeSet, HashMap};
99
use std::convert::TryFrom;
1010
use std::path::{Path, PathBuf};
1111

12-
use self::llvm_coverage::{get_counters, get_prf_data, read_covmap, Coverage, LLVMCovSections};
12+
use self::llvm_coverage::{Coverage, LLVMCovSections, get_counters, get_prf_data, read_covmap};
1313
use crate::traits::{SaveToStatsFolder, Sensor};
1414

1515
/// A sensor that automatically records the code coverage of the program through an array of counters.
@@ -92,14 +92,16 @@ impl CodeCoverageSensor {
9292

9393
#[coverage(off)]
9494
unsafe fn clear(&mut self) {
95-
for &coverage_idx in &self.needs_clearing {
96-
let coverage = &self.coverage[coverage_idx];
97-
let slice = std::slice::from_raw_parts_mut(coverage.start_counters, coverage.counters_len);
98-
for c in slice.iter_mut() {
99-
*c = 0;
95+
unsafe {
96+
for &coverage_idx in &self.needs_clearing {
97+
let coverage = &self.coverage[coverage_idx];
98+
let slice = std::slice::from_raw_parts_mut(coverage.start_counters, coverage.counters_len);
99+
for c in slice.iter_mut() {
100+
*c = 0;
101+
}
100102
}
103+
self.needs_clearing.clear();
101104
}
102-
self.needs_clearing.clear();
103105
}
104106
}
105107

fuzzcheck/src/fuzzer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ where
273273
}
274274
}
275275
#[coverage(off)]
276-
unsafe fn set_up_signal_handler(&mut self) {
276+
unsafe fn set_up_signal_handler(&mut self) { unsafe {
277277
let ptr = self as *mut Self;
278278
let (stack_ptr, stack_size) = set_signal_handlers(
279279
#[coverage(off)]
280280
move |sig| (*ptr).receive_signal(sig),
281281
);
282282
self.signal_handler_alt_stack = Some((stack_ptr, stack_size));
283-
}
283+
}}
284284
}
285285

286286
pub struct Fuzzer<T, M>

fuzzcheck/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
#![feature(stmt_expr_attributes)]
2929
// very very nice to use, but I guess not essential?
3030
#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)]
31-
// should be stabilised very soon
32-
#![feature(let_chains)]
33-
//
3431
// end nightly features
3532
//
3633
#![allow(clippy::nonstandard_macro_braces)]
@@ -220,11 +217,11 @@ pub use fuzzer::FuzzingResult;
220217
pub use fuzzer::PoolStorageIndex;
221218
#[doc(inline)]
222219
pub use fuzzer::ReasonForStopping;
220+
pub(crate) use mutators::CROSSOVER_RATE;
223221
#[doc(inline)]
224222
pub use mutators::DefaultMutator;
225223
#[doc(inline)]
226224
pub use mutators::MutatorExt;
227-
pub(crate) use mutators::CROSSOVER_RATE;
228225
#[doc(inline)]
229226
pub use sensors_and_pools::PoolExt;
230227
#[doc(inline)]

fuzzcheck/src/sensors_and_pools/allocations_sensor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,18 @@ where
188188
A: GlobalAlloc,
189189
{
190190
#[coverage(off)]
191-
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
191+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe {
192192
let ptr = self.0.alloc(layout);
193193
if ptr.is_null() {
194194
return ptr;
195195
}
196196
let size = layout.size();
197-
ALLOC_STATS.alloc(size);
197+
(*&raw mut ALLOC_STATS).alloc(size);
198198
ptr
199-
}
199+
}}
200200

201201
#[coverage(off)]
202-
unsafe fn realloc(&self, old_ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
202+
unsafe fn realloc(&self, old_ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { unsafe {
203203
let new_ptr = self.0.realloc(old_ptr, layout, new_size);
204204
if new_ptr.is_null() {
205205
return new_ptr;
@@ -210,15 +210,15 @@ where
210210
} else {
211211
(false, new_size - old_size)
212212
};
213-
ALLOC_STATS.realloc(new_size, shrink, delta);
213+
(*&raw mut ALLOC_STATS).realloc(new_size, shrink, delta);
214214
new_ptr
215-
}
215+
}}
216216
#[coverage(off)]
217217
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
218-
self.0.dealloc(ptr, layout);
218+
unsafe { self.0.dealloc(ptr, layout) };
219219

220220
let size = layout.size();
221-
ALLOC_STATS.dealloc(size);
221+
unsafe { (&raw mut ALLOC_STATS).as_mut() }.unwrap().dealloc(size);
222222
}
223223
}
224224

@@ -238,8 +238,8 @@ struct AllocationsStats {
238238
fn get_allocation_stats() -> AllocationsStats {
239239
unsafe {
240240
AllocationsStats {
241-
total_blocks: ALLOC_STATS.total_blocks.load(Ordering::SeqCst),
242-
total_bytes: ALLOC_STATS.total_bytes.load(Ordering::SeqCst),
241+
total_blocks: (*&raw mut ALLOC_STATS).total_blocks.load(Ordering::SeqCst),
242+
total_bytes: (*&raw mut ALLOC_STATS).total_bytes.load(Ordering::SeqCst),
243243
// curr_blocks: ALLOC_STATS.curr_blocks.load(Ordering::SeqCst),
244244
// curr_bytes: ALLOC_STATS.curr_bytes.load(Ordering::SeqCst),
245245
}

fuzzcheck/src/sensors_and_pools/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ pub use noop_sensor::NoopSensor;
3535
pub use simplest_to_activate_counter_pool::SimplestToActivateCounterPool;
3636
#[doc(inline)]
3737
pub use static_value_sensor::StaticValueSensor;
38+
pub(crate) use test_failure_pool::TEST_FAILURE;
3839
#[doc(inline)]
3940
pub use test_failure_pool::TestFailure;
4041
#[doc(inline)]
4142
pub use test_failure_pool::TestFailurePool;
4243
#[doc(inline)]
4344
pub use test_failure_pool::TestFailureSensor;
44-
pub(crate) use test_failure_pool::TEST_FAILURE;
4545
#[doc(inline)]
4646
pub use unique_values_pool::UniqueValuesPool;
4747
#[doc(inline)]
@@ -86,7 +86,7 @@ pub trait SensorExt: Sensor {
8686
/// # use fuzzcheck::sensors_and_pools::StaticValueSensor;
8787
/// # static mut COUNTERS: [u64; 2] = [0; 2];
8888
/// # // inside the fuzz test, you can create the sensor as follows
89-
/// # let sensor = unsafe { StaticValueSensor::new(&mut COUNTERS, [0, 0]) };
89+
/// # let sensor = unsafe { StaticValueSensor::new(&mut *&raw mut COUNTERS, [0, 0]) };
9090
/// let sensor = sensor.map(|observations| {
9191
/// let sum = observations.iter().sum::<u64>();
9292
/// (observations, sum)

0 commit comments

Comments
 (0)