about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/afl-fuzz-init.c1
-rw-r--r--src/afl-fuzz-queue.c22
2 files changed, 14 insertions, 9 deletions
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index 1bccff8f..19a8d77b 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -2358,6 +2358,7 @@ void check_asan_opts(afl_state_t *afl) {
       FATAL("Custom ASAN_OPTIONS set without symbolize=0 - please fix!");
 
     }
+
 #endif
 
   }
diff --git a/src/afl-fuzz-queue.c b/src/afl-fuzz-queue.c
index 02e66a4e..d107dbc8 100644
--- a/src/afl-fuzz-queue.c
+++ b/src/afl-fuzz-queue.c
@@ -914,20 +914,22 @@ inline void queue_testcase_retake_mem(afl_state_t *afl, struct queue_entry *q,
 
   if (likely(q->testcase_buf)) {
 
+    u32 is_same = in == q->testcase_buf;
+
     if (likely(len != old_len)) {
 
-      afl->q_testcase_cache_size = afl->q_testcase_cache_size + len - old_len;
-      q->testcase_buf = realloc(q->testcase_buf, len);
+      u8 *ptr = realloc(q->testcase_buf, len);
 
-      if (unlikely(!q->testcase_buf)) {
+      if (likely(ptr)) {
 
-        PFATAL("Unable to malloc '%s' with len %d", q->fname, len);
+        q->testcase_buf = ptr;
+        afl->q_testcase_cache_size = afl->q_testcase_cache_size + len - old_len;
 
       }
 
     }
 
-    memcpy(q->testcase_buf, in, len);
+    if (unlikely(!is_same)) { memcpy(q->testcase_buf, in, len); }
 
   }
 
@@ -986,10 +988,12 @@ 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.
          Get a random one which is not in use */
 
-      if (unlikely(afl->q_testcase_cache_size + len >= 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_entries))) {
+      if (unlikely(afl->q_testcase_cache_size + len >=
+                       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_entries))) {
 
         if (afl->q_testcase_max_cache_count > afl->q_testcase_cache_count) {