Skip to content

Commit 96ef708

Browse files
committed
using unbiased rand_below
1 parent 78eaa6b commit 96ef708

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/afl-fuzz.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,12 @@ static inline u32 rand_below(afl_state_t *afl, u32 limit) {
10271027

10281028
}
10291029

1030-
return rand_next(afl) % limit;
1030+
/* Modulo is biased - we don't want our fuzzing to be biased so let's do it right. */
1031+
u64 unbiased_rnd;
1032+
do {
1033+
unbiased_rnd = rand_next(afl);
1034+
} while (unbiased_rnd >= (UINT64_MAX - (UINT64_MAX % limit)));
1035+
return unbiased_rnd % limit;
10311036

10321037
}
10331038

0 commit comments

Comments
 (0)