fix testcache bug

This commit is contained in:
van Hauser
2020-10-24 16:28:46 +02:00
parent e5c2779d56
commit e5f30c6908
2 changed files with 14 additions and 9 deletions

View File

@ -2358,6 +2358,7 @@ void check_asan_opts(afl_state_t *afl) {
FATAL("Custom ASAN_OPTIONS set without symbolize=0 - please fix!"); FATAL("Custom ASAN_OPTIONS set without symbolize=0 - please fix!");
} }
#endif #endif
} }

View File

@ -914,20 +914,22 @@ inline void queue_testcase_retake_mem(afl_state_t *afl, struct queue_entry *q,
if (likely(q->testcase_buf)) { if (likely(q->testcase_buf)) {
u32 is_same = in == q->testcase_buf;
if (likely(len != old_len)) { if (likely(len != old_len)) {
u8 *ptr = realloc(q->testcase_buf, len);
if (likely(ptr)) {
q->testcase_buf = ptr;
afl->q_testcase_cache_size = afl->q_testcase_cache_size + len - old_len; afl->q_testcase_cache_size = afl->q_testcase_cache_size + len - old_len;
q->testcase_buf = realloc(q->testcase_buf, len);
if (unlikely(!q->testcase_buf)) {
PFATAL("Unable to malloc '%s' with len %d", q->fname, len);
} }
} }
memcpy(q->testcase_buf, in, len); if (unlikely(!is_same)) { memcpy(q->testcase_buf, in, len); }
} }
@ -986,8 +988,10 @@ inline u8 *queue_testcase_get(afl_state_t *afl, struct queue_entry *q) {
/* Cache full. We neet to evict one or more to map one. /* Cache full. We neet to evict one or more to map one.
Get a random one which is not in use */ Get a random one which is not in use */
if (unlikely(afl->q_testcase_cache_size + len >= afl->q_testcase_max_cache_size && if (unlikely(afl->q_testcase_cache_size + len >=
(afl->q_testcase_cache_count < afl->q_testcase_max_cache_entries && afl->q_testcase_max_cache_size &&
(afl->q_testcase_cache_count <
afl->q_testcase_max_cache_entries &&
afl->q_testcase_max_cache_count < afl->q_testcase_max_cache_count <
afl->q_testcase_max_cache_entries))) { afl->q_testcase_max_cache_entries))) {