Skip to content

Commit 94ab7cb

Browse files
committed
fix ijon macros
1 parent d2ab3bd commit 94ab7cb

File tree

2 files changed

+48
-35
lines changed

2 files changed

+48
-35
lines changed

afl/examples/maze.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ The maze:
3737
cddbddcccacaaaccaaaaaabbbbbbbbbbaaccccccccccccaaccaabbbbbbbbbbbbbbbbbbbbbbbbbaacccccccccccccccccccccccccccccdddddddddddddddddddddddddddddbbbbbbbbbbbbbbbd
3838
*/
3939

40-
use afl::ijon_set;
4140
use afl::ijon_hashint;
41+
use afl::ijon_hashstr;
42+
use afl::ijon_set;
43+
use std::ffi::CString;
4244

4345
fn main() {
4446
afl::fuzz!(|data: &[u8]| {
@@ -190,7 +192,6 @@ fn main() {
190192
}
191193

192194
ijon_set!(ijon_hashint(pos.0 as u32, pos.1 as u32));
193-
194195
}
195196
});
196197
}

afl/src/lib.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use std::env;
99
use std::io::{self, Read};
10+
use std::os::raw::c_char;
1011
use std::panic;
1112

1213
// those functions are provided by the afl-compiler-rt static library
@@ -28,7 +29,7 @@ unsafe extern "C" {
2829
pub fn ijon_reset_state();
2930
pub fn ijon_simple_hash(x: u64) -> u64;
3031
pub fn ijon_hashint(old: u32, val: u32) -> u32;
31-
pub fn ijon_hashstr(old: u32, val: *const u8) -> u32;
32+
pub fn ijon_hashstr(old: u32, val: *const c_char) -> u32;
3233
pub fn ijon_hashmen(old: u32, val: *const u8, len: usize) -> u32;
3334
pub fn ijon_hashstack_backtrace() -> u32;
3435
pub fn ijon_hashstack() -> u32;
@@ -45,11 +46,12 @@ macro_rules! ijon_inc {
4546
static LOC_CACHE: AtomicU32 = AtomicU32::new(0);
4647
let mut loc = LOC_CACHE.load(Ordering::Relaxed);
4748
if loc == 0 {
48-
let new_val = ijon_hashstr(line!(), file!());
49+
let cfile = CString::new(file!()).unwrap();
50+
let new_val = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
4951
LOC_CACHE.store(new_val, Ordering::Relaxed);
5052
loc = new_val;
5153
}
52-
ijon_inc(loc, $x);
54+
unsafe { ijon_inc(loc, $x) };
5355
}};
5456
}
5557

@@ -60,11 +62,12 @@ macro_rules! ijon_max {
6062
static LOC_CACHE: AtomicU32 = AtomicU32::new(0);
6163
let mut loc = LOC_CACHE.load(Ordering::Relaxed);
6264
if loc == 0 {
63-
let new_val = ijon_hashstr(line!(), file!());
65+
let cfile = CString::new(file!()).unwrap();
66+
let new_val = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
6467
LOC_CACHE.store(new_val, Ordering::Relaxed);
6568
loc = new_val;
6669
}
67-
ijon_max_variadic(loc, $($x),+, 0u64);
70+
unsafe { ijon_max_variadic(loc, $($x),+, 0u64) };
6871
}};
6972
}
7073

@@ -75,11 +78,12 @@ macro_rules! ijon_min {
7578
static LOC_CACHE: AtomicU32 = AtomicU32::new(0);
7679
let mut loc = LOC_CACHE.load(Ordering::Relaxed);
7780
if loc == 0 {
78-
let new_val = ijon_hashstr(line!(), file!());
81+
let cfile = CString::new(file!()).unwrap();
82+
let new_val = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
7983
LOC_CACHE.store(new_val, Ordering::Relaxed);
8084
loc = new_val;
8185
}
82-
ijon_min_variadic(loc, $($x),+, 0u64);
86+
unsafe { ijon_min_variadic(loc, $($x),+, 0u64) };
8387
}};
8488
}
8589

@@ -90,43 +94,45 @@ macro_rules! ijon_set {
9094
static LOC_CACHE: AtomicU32 = AtomicU32::new(0);
9195
let mut loc = LOC_CACHE.load(Ordering::Relaxed);
9296
if loc == 0 {
93-
let new_val = ijon_hashstr(line!(), file!());
97+
let cfile = CString::new(file!()).unwrap();
98+
let new_val = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
9499
LOC_CACHE.store(new_val, Ordering::Relaxed);
95100
loc = new_val;
96101
}
97-
ijon_set(loc, $x);
102+
unsafe { ijon_set(loc, $x) };
98103
}};
99104
}
100105

101106
#[macro_export]
102107
macro_rules! ijon_state {
103108
($n:expr) => {
104-
ijon_xor_state($n)
109+
unsafe { ijon_xor_state($n) }
105110
};
106111
}
107112

108113
#[macro_export]
109114
macro_rules! ijon_ctx {
110115
($x:expr) => {{
111-
let hash = ijon_hashstr(line!(), file!());
112-
ijon_xor_state(hash);
116+
let cfile = CString::new(file!()).unwrap();
117+
let hash = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
118+
unsafe { ijon_xor_state(hash) };
113119
let temp = $x;
114-
ijon_xor_state(hash);
120+
unsafe { ijon_xor_state(hash) };
115121
temp
116122
}};
117123
}
118124

119125
#[macro_export]
120126
macro_rules! ijon_max_at {
121127
($addr:expr, $x:expr) => {
122-
ijon_max($addr, $x)
128+
unsafe { ijon_max($addr, $x) }
123129
};
124130
}
125131

126132
#[macro_export]
127133
macro_rules! ijon_min_at {
128134
($addr:expr, $x:expr) => {
129-
ijon_min($addr, $x)
135+
unsafe { ijon_min($addr, $x) }
130136
};
131137
}
132138

@@ -140,38 +146,42 @@ macro_rules! _ijon_abs_dist {
140146
#[macro_export]
141147
macro_rules! ijon_bits {
142148
($x:expr) => {
143-
ijon_set(ijon_hashint(
144-
ijon_hashstack(),
145-
if $x == 0 {
146-
0
147-
} else {
148-
$x.leading_zeros() as u32
149-
},
150-
))
149+
unsafe {
150+
ijon_set(ijon_hashint(
151+
ijon_hashstack(),
152+
if $x == 0 {
153+
0
154+
} else {
155+
$x.leading_zeros() as u32
156+
},
157+
))
158+
}
151159
};
152160
}
153161

154162
#[macro_export]
155163
macro_rules! ijon_strdist {
156164
($x:expr, $y:expr) => {
157-
ijon_set(ijon_hashint(ijon_hashstack(), ijon_strdist($x, $y)))
165+
unsafe { ijon_set(ijon_hashint(ijon_hashstack(), ijon_strdist($x, $y))) }
158166
};
159167
}
160168

161169
#[macro_export]
162170
macro_rules! ijon_dist {
163171
($x:expr, $y:expr) => {
164-
ijon_set(ijon_hashint(
165-
ijon_hashstack(),
166-
$crate::_ijon_abs_dist!($x, $y),
167-
))
172+
unsafe {
173+
ijon_set(ijon_hashint(
174+
ijon_hashstack(),
175+
$crate::_ijon_abs_dist!($x, $y),
176+
))
177+
}
168178
};
169179
}
170180

171181
#[macro_export]
172182
macro_rules! ijon_cmp {
173183
($x:expr, $y:expr) => {
174-
ijon_inc(ijon_hashint(ijon_hashstack(), ($x ^ $y).count_ones()))
184+
unsafe { ijon_inc(ijon_hashint(ijon_hashstack(), ($x ^ $y).count_ones())) }
175185
};
176186
}
177187

@@ -182,11 +192,12 @@ macro_rules! ijon_stack_max {
182192
static LOC: AtomicU32 = AtomicU32::new(0);
183193
let mut loc = LOC.load(Ordering::Relaxed);
184194
if loc == 0 {
185-
let new_val = ijon_hashstr(line!(), file!());
195+
let cfile = CString::new(file!()).unwrap();
196+
let new_val = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
186197
LOC.store(new_val, Ordering::Relaxed);
187198
loc = new_val;
188199
}
189-
ijon_max(ijon_hashint(loc, ijon_hashstack()), $x);
200+
unsafe { ijon_max(ijon_hashint(loc, ijon_hashstack()), $x) };
190201
}};
191202
}
192203

@@ -197,11 +208,12 @@ macro_rules! ijon_stack_min {
197208
static LOC: AtomicU32 = AtomicU32::new(0);
198209
let mut loc = LOC.load(Ordering::Relaxed);
199210
if loc == 0 {
200-
let new_val = ijon_hashstr(line!(), file!());
211+
let cfile = CString::new(file!()).unwrap();
212+
let new_val = unsafe { ijon_hashstr(line!(), cfile.as_ptr()) };
201213
LOC.store(new_val, Ordering::Relaxed);
202214
loc = new_val;
203215
}
204-
ijon_min(ijon_hashint(loc, ijon_hashstack()), $x);
216+
unsafe { ijon_min(ijon_hashint(loc, ijon_hashstack()), $x) };
205217
}};
206218
}
207219

0 commit comments

Comments
 (0)