small enhancements and code-format

This commit is contained in:
van Hauser
2020-04-02 16:41:33 +02:00
parent 5602a09cc6
commit e8e6dbf839
4 changed files with 40 additions and 33 deletions

View File

@ -935,13 +935,13 @@ u8 input_to_state_stage(afl_state_t *afl, u8 *orig_buf, u8 *buf, u32 len,
static inline u32 rand_below(afl_state_t *afl, u32 limit) { static inline u32 rand_below(afl_state_t *afl, u32 limit) {
#ifdef HAVE_ARC4RANDOM #ifdef HAVE_ARC4RANDOM
if (afl->fixed_seed) { return random() % limit; } if (unlikely(afl->fixed_seed)) { return random() % limit; }
/* The boundary not being necessarily a power of 2, /* The boundary not being necessarily a power of 2,
we need to ensure the result uniformity. */ we need to ensure the result uniformity. */
return arc4random_uniform(limit); return arc4random_uniform(limit);
#else #else
if (!afl->fixed_seed && unlikely(!afl->rand_cnt--)) { if (unlikely(!afl->rand_cnt--) && likely(!afl->fixed_seed)) {
ck_read(afl->fsrv.dev_urandom_fd, &afl->rand_seed, sizeof(afl->rand_seed), ck_read(afl->fsrv.dev_urandom_fd, &afl->rand_seed, sizeof(afl->rand_seed),
"/dev/urandom"); "/dev/urandom");
@ -957,7 +957,7 @@ static inline u32 rand_below(afl_state_t *afl, u32 limit) {
static inline u32 get_rand_seed(afl_state_t *afl) { static inline u32 get_rand_seed(afl_state_t *afl) {
if (afl->fixed_seed) return (u32)afl->init_seed; if (unlikely(afl->fixed_seed)) return (u32)afl->init_seed;
return afl->rand_seed[0]; return afl->rand_seed[0];
} }

View File

@ -107,8 +107,7 @@ static inline void list_append(list_t *list, void *el) {
if (!el_box) FATAL("foreach over uninitialized list"); \ if (!el_box) FATAL("foreach over uninitialized list"); \
while (el_box != head) { \ while (el_box != head) { \
\ \
__attribute__((unused)) \ __attribute__((unused)) type *el = (type *)((el_box)->data); \
type *el = (type *)((el_box)->data); \
/* get next so el_box can be unlinked */ \ /* get next so el_box can be unlinked */ \
element_t *next = el_box->next; \ element_t *next = el_box->next; \
{block}; \ {block}; \

View File

@ -36,6 +36,7 @@ void write_stats_file(afl_state_t *afl, double bitmap_cvg, double stability,
u8 fn[PATH_MAX]; u8 fn[PATH_MAX];
s32 fd; s32 fd;
FILE * f; FILE * f;
uint32_t t_bytes = count_non_255_bytes(afl->virgin_bits);
snprintf(fn, PATH_MAX, "%s/fuzzer_stats", afl->out_dir); snprintf(fn, PATH_MAX, "%s/fuzzer_stats", afl->out_dir);
@ -97,6 +98,8 @@ void write_stats_file(afl_state_t *afl, double bitmap_cvg, double stability,
"exec_timeout : %u\n" "exec_timeout : %u\n"
"slowest_exec_ms : %u\n" "slowest_exec_ms : %u\n"
"peak_rss_mb : %lu\n" "peak_rss_mb : %lu\n"
"var_byte_count : %u\n"
"found_edges : %u\n"
"afl_banner : %s\n" "afl_banner : %s\n"
"afl_version : " VERSION "afl_version : " VERSION
"\n" "\n"
@ -119,9 +122,10 @@ void write_stats_file(afl_state_t *afl, double bitmap_cvg, double stability,
#else #else
(unsigned long int)(rus.ru_maxrss >> 10), (unsigned long int)(rus.ru_maxrss >> 10),
#endif #endif
afl->use_banner, afl->unicorn_mode ? "unicorn" : "", afl->var_byte_count, t_bytes, afl->use_banner,
afl->qemu_mode ? "qemu " : "", afl->dumb_mode ? " dumb " : "", afl->unicorn_mode ? "unicorn" : "", afl->qemu_mode ? "qemu " : "",
afl->no_forkserver ? "no_fsrv " : "", afl->crash_mode ? "crash " : "", afl->dumb_mode ? " dumb " : "", afl->no_forkserver ? "no_fsrv " : "",
afl->crash_mode ? "crash " : "",
afl->persistent_mode ? "persistent " : "", afl->persistent_mode ? "persistent " : "",
afl->deferred_mode ? "deferred " : "", afl->deferred_mode ? "deferred " : "",
(afl->unicorn_mode || afl->qemu_mode || afl->dumb_mode || (afl->unicorn_mode || afl->qemu_mode || afl->dumb_mode ||
@ -257,7 +261,7 @@ void show_stats(afl_state_t *afl) {
t_byte_ratio = ((double)t_bytes * 100) / MAP_SIZE; t_byte_ratio = ((double)t_bytes * 100) / MAP_SIZE;
if (t_bytes) if (t_bytes)
stab_ratio = 100 - ((double)afl->var_byte_count) * 100 / t_bytes; stab_ratio = 100 - (((double)afl->var_byte_count) * 100) / t_bytes;
else else
stab_ratio = 100; stab_ratio = 100;

View File

@ -691,6 +691,7 @@ int main(int argc, char **argv_orig, char **envp) {
if (afl->fixed_seed) OKF("Running with fixed seed: %u", (u32)afl->init_seed); if (afl->fixed_seed) OKF("Running with fixed seed: %u", (u32)afl->init_seed);
srandom((u32)afl->init_seed); srandom((u32)afl->init_seed);
srand((u32)afl->init_seed); // in case it is a different implementation
if (afl->use_radamsa) { if (afl->use_radamsa) {
@ -723,9 +724,12 @@ int main(int argc, char **argv_orig, char **envp) {
#if defined(__SANITIZE_ADDRESS__) #if defined(__SANITIZE_ADDRESS__)
if (afl->fsrv.mem_limit) { if (afl->fsrv.mem_limit) {
WARNF("in the ASAN build we disable all memory limits"); WARNF("in the ASAN build we disable all memory limits");
afl->fsrv.mem_limit = 0; afl->fsrv.mem_limit = 0;
} }
#endif #endif
setup_signal_handlers(); setup_signal_handlers();