Skip to content

Commit c604d2d

Browse files
authored
Fix incorrect autotokens check on macos (#3316)
* Fix incorrect autotokens check on macos * Fix clippy
1 parent a2fc294 commit c604d2d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

libafl_targets/src/coverage.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,28 @@ pub use __afl_fuzz_len as INPUT_LENGTH_PTR;
5656
pub use __afl_fuzz_ptr as INPUT_PTR;
5757
pub use __afl_sharedmem_fuzzing as SHM_FUZZING;
5858

59+
/// Check if we have enabled autotokens
60+
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
61+
pub(crate) fn has_autotokens() -> bool {
62+
unsafe {
63+
!__token_start.is_null()
64+
&& !__token_stop.is_null()
65+
&& __token_stop.offset_from(__token_start) != 0
66+
}
67+
}
68+
5969
/// Return Tokens from the compile-time token section
6070
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
6171
pub fn autotokens() -> Result<Tokens, Error> {
6272
// # Safety
6373
// All values are checked before dereferencing.
6474

6575
unsafe {
66-
if __token_start.is_null() || __token_stop.is_null() {
67-
Ok(Tokens::default())
68-
} else {
76+
if has_autotokens() {
6977
// we can safely unwrap
7078
Tokens::from_mut_ptrs(__token_start, __token_stop)
79+
} else {
80+
Ok(Tokens::default())
7181
}
7282
}
7383
}

libafl_targets/src/forkserver.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ use crate::cmps::EXTENDED_CMPLOG_MAP_PTR;
3333
use crate::cmps::{AflppCmpLogMap, CMPLOG_MAP_PTR};
3434
use crate::coverage::{__afl_map_size, EDGES_MAP_PTR, INPUT_LENGTH_PTR, INPUT_PTR, SHM_FUZZING};
3535
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
36-
use crate::coverage::{__token_start, __token_stop};
36+
use crate::{
37+
coverage::{__token_start, __token_stop},
38+
has_autotokens,
39+
};
3740

3841
/// SAFETY:
3942
///
@@ -124,6 +127,7 @@ fn map_shared_memory_common<SHM: ShMemProvider>(
124127
} else {
125128
map_size_default_fallback
126129
};
130+
127131
let shmem = shmem_provider.shmem_from_id_and_size(ShMemId::from_string(&id_str), map_size)?;
128132

129133
Ok(shmem_into_raw(shmem))
@@ -413,7 +417,7 @@ fn start_forkserver_internal<P: ForkserverParent>(
413417
forkserver_parent: &mut P,
414418
) -> Result<ForkserverState, Error> {
415419
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
416-
let autotokens_on = unsafe { !__token_start.is_null() && !__token_stop.is_null() };
420+
let autotokens_on = has_autotokens();
417421
let sharedmem_fuzzing = unsafe { SHM_FUZZING == 1 };
418422

419423
// Parent supports testcases via shared map - and the user wants to use it. Tell AFL.

0 commit comments

Comments
 (0)