Skip to content

Commit 9195245

Browse files
authored
Proposed fix for issue #3094, whereby all conditional comparisons are treat as 1 byte (rather than 2, 4, or 8) (#3095)
1 parent f73d47d commit 9195245

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

libafl_targets/src/sancov_cmp.c

+16-13
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88
#include "cmplog.h"
99
#endif
1010

11-
// Note: for RETADDR to give us the fuzz target caller address we need
11+
// Note: for RETADDR to give us the fuzz target caller address we need
1212
// to guarantee that this code is inlined. `inline` keyword provides
1313
// no such guarantees, but a macro does.
1414
#ifdef SANCOV_VALUE_PROFILE
1515
#define SANCOV_VALUE_PROFILE_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
16-
k &= CMP_MAP_SIZE - 1; \
17-
__libafl_targets_value_profile1(k, arg1, arg2);
16+
k &= CMP_MAP_SIZE - 1; \
17+
__libafl_targets_value_profile##arg_size(k, arg1, arg2);
1818
#else
1919
#define SANCOV_VALUE_PROFILE_CALL(k, arg_size, arg1, arg2, arg1_is_const)
2020
#endif
2121

2222
#ifdef SANCOV_CMPLOG
23-
#define SANCOV_CMPLOG_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
24-
k &= CMPLOG_MAP_W - 1; \
25-
cmplog_instructions_checked(k, arg_size, (uint64_t)arg1, (uint64_t)arg2, arg1_is_const);
23+
#define SANCOV_CMPLOG_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
24+
k &= CMPLOG_MAP_W - 1; \
25+
cmplog_instructions_checked(k, arg_size, (uint64_t)arg1, (uint64_t)arg2, \
26+
arg1_is_const);
2627
#else
2728
#define SANCOV_CMPLOG_CALL(k, arg_size, arg1, arg2, arg1_is_const)
2829
#endif
2930

30-
#define HANDLE_SANCOV_TRACE_CMP(arg_size, arg1, arg2, arg1_is_const) { \
31-
uintptr_t k = RETADDR; \
32-
k = (k >> 4) ^ (k << 8); \
33-
SANCOV_VALUE_PROFILE_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
34-
SANCOV_CMPLOG_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
35-
}
31+
#define HANDLE_SANCOV_TRACE_CMP(arg_size, arg1, arg2, arg1_is_const) \
32+
{ \
33+
uintptr_t k = RETADDR; \
34+
k = (k >> 4) ^ (k << 8); \
35+
SANCOV_VALUE_PROFILE_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
36+
SANCOV_CMPLOG_CALL(k, arg_size, arg1, arg2, arg1_is_const) \
37+
}
3638

3739
void __sanitizer_cov_trace_cmp1(uint8_t arg1, uint8_t arg2) {
3840
HANDLE_SANCOV_TRACE_CMP(1, arg1, arg2, 0);
@@ -80,7 +82,8 @@ void __sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases) {
8082
#endif
8183
#ifdef SANCOV_CMPLOG
8284
k &= CMPLOG_MAP_W - 1;
83-
// Note: cases[i + 2] are the constant values, so keep them in arg1 and indicate that it's const
85+
// Note: cases[i + 2] are the constant values, so keep them in arg1 and
86+
// indicate that it's const
8487
cmplog_instructions_checked(k, cases[1] / 8, cases[i + 2], val, 1);
8588
#endif
8689
}

libafl_targets/src/windows_asan.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ unsafe extern "C" {
2929
///
3030
/// # Safety
3131
/// Calls the unsafe `__sanitizer_set_death_callback` symbol, but should be safe to call otherwise.
32-
pub unsafe fn setup_asan_callback<E, EM, I, OF, S, Z>(
33-
_executor: &E,
34-
_event_mgr: &EM,
35-
_fuzzer: &Z,
36-
) where
32+
pub unsafe fn setup_asan_callback<E, EM, I, OF, S, Z>(_executor: &E, _event_mgr: &EM, _fuzzer: &Z)
33+
where
3734
E: Executor<EM, I, S, Z> + HasObservers,
3835
E::Observers: ObserversTuple<I, S>,
3936
EM: EventFirer<I, S> + EventRestarter<S>,

0 commit comments

Comments
 (0)