Skip to content

Commit

Permalink
Fixup serdeany_autoreg (#2721)
Browse files Browse the repository at this point in the history
* fixup serdeany_autoreg

* missed a spot

* remove explicit checks in ps1 as this is set by Cargo.toml
  • Loading branch information
addisoncrump authored Nov 24, 2024
1 parent 959ecb3 commit e53dd4e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
19 changes: 18 additions & 1 deletion libafl/src/executors/forkserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ where
min_input_size: self.min_input_size,
max_input_size: self.max_input_size,
timeout,
#[cfg(feature = "regex")]
asan_obs: self
.asan_obs
.clone()
Expand Down Expand Up @@ -956,6 +957,7 @@ where
min_input_size: self.min_input_size,
max_input_size: self.max_input_size,
timeout,
#[cfg(feature = "regex")]
asan_obs: self
.asan_obs
.clone()
Expand Down Expand Up @@ -1003,7 +1005,7 @@ where
0,
self.is_persistent,
self.is_deferred_frksrv,
self.asan_obs.is_some(),
self.has_asan_obs(),
self.map_size,
self.debug_child,
self.kill_signal.unwrap_or(KILL_SIGNAL_DEFAULT),
Expand Down Expand Up @@ -1456,6 +1458,18 @@ where
self.kill_signal = Some(kill_signal);
self
}

/// Determine if the asan observer is present (always false if feature "regex" is disabled)
#[cfg(feature = "regex")]
pub fn has_asan_obs(&self) -> bool {
self.asan_obs.is_some()
}

/// Determine if the asan observer is present (always false if feature "regex" is disabled)
#[cfg(not(feature = "regex"))]
pub fn has_asan_obs(&self) -> bool {
false
}
}

impl<'a> ForkserverExecutorBuilder<'a, NopTargetBytesConverter<BytesInput>, UnixShMemProvider> {
Expand Down Expand Up @@ -1485,6 +1499,7 @@ impl<'a> ForkserverExecutorBuilder<'a, NopTargetBytesConverter<BytesInput>, Unix
min_input_size: MIN_INPUT_SIZE_DEFAULT,
kill_signal: None,
timeout: None,
#[cfg(feature = "regex")]
asan_obs: None,
crash_exitcode: None,
target_bytes_converter: NopTargetBytesConverter::new(),
Expand Down Expand Up @@ -1517,6 +1532,7 @@ impl<'a, TC> ForkserverExecutorBuilder<'a, TC, UnixShMemProvider> {
min_input_size: self.min_input_size,
kill_signal: self.kill_signal,
timeout: self.timeout,
#[cfg(feature = "regex")]
asan_obs: self.asan_obs,
crash_exitcode: self.crash_exitcode,
target_bytes_converter: self.target_bytes_converter,
Expand Down Expand Up @@ -1549,6 +1565,7 @@ impl<'a, TC, SP> ForkserverExecutorBuilder<'a, TC, SP> {
min_input_size: self.min_input_size,
kill_signal: self.kill_signal,
timeout: self.timeout,
#[cfg(feature = "regex")]
asan_obs: self.asan_obs,
crash_exitcode: self.crash_exitcode,
target_bytes_converter,
Expand Down
4 changes: 1 addition & 3 deletions libafl/src/stages/verify_timeouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ use std::{cell::RefCell, collections::VecDeque, fmt::Debug, marker::PhantomData,
use libafl_bolts::Error;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

#[cfg(not(miri))]
use crate::inputs::BytesInput;
use crate::{
corpus::Corpus,
executors::{Executor, HasObservers, HasTimeout},
inputs::UsesInput,
inputs::{BytesInput, UsesInput},
observers::ObserversTuple,
stages::Stage,
state::{HasCorpus, State, UsesState},
Expand Down
28 changes: 24 additions & 4 deletions libafl_bolts/src/serdeany.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,26 @@ macro_rules! create_register {
($struct_type:ty) => {};
}

/// Manually register a `SerdeAny` type in the [`RegistryBuilder`]
///
/// Do nothing with the `serdeany_autoreg` feature, as this will be previously registered by ctor.
#[cfg(all(feature = "serdeany_autoreg", not(miri)))]
#[macro_export]
macro_rules! create_manual_register {
($struct_type:ty) => {};
}

/// Manually register a `SerdeAny` type in the [`RegistryBuilder`]
///
/// Do nothing with the `serdeany_autoreg` feature, as this will be previously registered by ctor.
#[cfg(not(all(feature = "serdeany_autoreg", not(miri))))]
#[macro_export]
macro_rules! create_manual_register {
($struct_type:ty) => {
$crate::serdeany::RegistryBuilder::register::<$struct_type>();
};
}

/// Implement a [`SerdeAny`], registering it in the [`RegistryBuilder`] when on std
#[macro_export]
macro_rules! impl_serdeany {
Expand Down Expand Up @@ -853,15 +873,16 @@ macro_rules! impl_serdeany {
}
}

#[cfg(any(not(feature = "serdeany_autoreg"), miri))]
impl< $( $lt $( : $clt $(+ $dlt )* )? ),+ > $struct_name < $( $lt ),+ > {

/// Manually register this type at a later point in time
///
/// # Safety
/// This may never be called concurrently as it dereferences the `RegistryBuilder` without acquiring a lock.
pub unsafe fn register() {
$crate::serdeany::RegistryBuilder::register::<$struct_name < $( $lt ),+ >>();
$(
$crate::create_manual_register!($struct_name < $( $opt ),+ >);
)*
}
}

Expand Down Expand Up @@ -894,15 +915,14 @@ macro_rules! impl_serdeany {
}
}

#[cfg(any(not(feature = "serdeany_autoreg"), miri))]
impl $struct_name {
/// Manually register this type at a later point in time
///
/// # Safety
/// This may never be called concurrently as it dereferences the `RegistryBuilder` without acquiring a lock.
#[allow(unused)]
pub unsafe fn register() {
$crate::serdeany::RegistryBuilder::register::<$struct_name>();
$crate::create_manual_register!($struct_name);
}
}

Expand Down
30 changes: 2 additions & 28 deletions scripts/clippy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@ function Run-Clippy {

try {
$env:RUST_BACKTRACE = "full"
cargo +nightly clippy --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace `
-D clippy::all `
-D clippy::pedantic `
-W clippy::similar_names `
-A clippy::type_repetition_in_bounds `
-A clippy::missing-errors-doc `
-A clippy::cast-possible-truncation `
-A clippy::used-underscore-binding `
-A clippy::ptr-as-ptr `
-A clippy::missing-panics-doc `
-A clippy::missing-docs-in-private-items `
-A clippy::unseparated-literal-suffix `
-A clippy::module-name-repetitions `
-A clippy::unreadable-literal
cargo +nightly clippy --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace

# Exit unsuccessfully on clippy error
if (!$?) {
Expand Down Expand Up @@ -68,20 +55,7 @@ else {

# First run it on all default members
$env:RUST_BACKTRACE = "full"
cargo +nightly clippy --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace `
-D clippy::all `
-D clippy::pedantic `
-W clippy::similar_names `
-A clippy::type_repetition_in_bounds `
-A clippy::missing-errors-doc `
-A clippy::cast-possible-truncation `
-A clippy::used-underscore-binding `
-A clippy::ptr-as-ptr `
-A clippy::missing-panics-doc `
-A clippy::missing-docs-in-private-items `
-A clippy::unseparated-literal-suffix `
-A clippy::module-name-repetitions `
-A clippy::unreadable-literal
cargo +nightly clippy --all-features --no-deps --tests --examples --benches -- -Z macro-backtrace

# Exit unsuccessfully on clippy error
if (!$?) {
Expand Down

0 comments on commit e53dd4e

Please sign in to comment.