about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDominik Maier <domenukk@gmail.com>2020-06-22 21:58:16 +0200
committerDominik Maier <domenukk@gmail.com>2020-06-22 21:58:23 +0200
commit7119bf5d860657dab7afb60fab8b7ad5dc0ef222 (patch)
tree8146668f22141e8f86627e451ad9d65cf99314d1 /src
parentea1222b33fb5e97165f649168b812d83ed1ed8c4 (diff)
downloadafl++-7119bf5d860657dab7afb60fab8b7ad5dc0ef222.tar.gz
Added rand, hash unittests
Diffstat (limited to 'src')
-rw-r--r--src/afl-fuzz-one.c2
-rw-r--r--src/afl-fuzz.c9
-rw-r--r--src/afl-performance.c10
3 files changed, 13 insertions, 8 deletions
diff --git a/src/afl-fuzz-one.c b/src/afl-fuzz-one.c
index e42a323d..60db9777 100644
--- a/src/afl-fuzz-one.c
+++ b/src/afl-fuzz-one.c
@@ -2458,7 +2458,7 @@ radamsa_stage:
   for (afl->stage_cur = 0; afl->stage_cur < afl->stage_max; ++afl->stage_cur) {
 
     u32 new_len = afl->radamsa_mutate_ptr(save_buf, len, new_buf, max_len,
-                                          get_rand_seed(afl));
+                                          rand_get_seed(afl));
 
     if (new_len) {
 
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index bfd7cb33..c8083f71 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -289,7 +289,7 @@ int main(int argc, char **argv_orig, char **envp) {
   doc_path = access(DOC_PATH, F_OK) != 0 ? (u8 *)"docs" : (u8 *)DOC_PATH;
 
   gettimeofday(&tv, &tz);
-  afl->init_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
+  rand_set_seed(afl, tv.tv_sec ^ tv.tv_usec ^ getpid());
 
   while ((opt = getopt(argc, argv,
                        "+c:i:I:o:f:m:t:T:dnCB:S:M:x:QNUWe:p:s:V:E:L:hRP:")) >
@@ -311,7 +311,7 @@ int main(int argc, char **argv_orig, char **envp) {
 
       case 's': {
 
-        afl->init_seed = strtoul(optarg, 0L, 10);
+        rand_set_seed(afl, strtoul(optarg, 0L, 10));
         afl->fixed_seed = 1;
         break;
 
@@ -833,11 +833,6 @@ int main(int argc, char **argv_orig, char **envp) {
 
   }
 
-  afl->rand_seed[0] = hash64((void *)&afl->init_seed, sizeof(u32), HASH_CONST);
-  afl->rand_seed[1] = afl->rand_seed[0] ^ 0x1234567890abcdef;
-  afl->rand_seed[2] = afl->rand_seed[0] & 0x0123456789abcdef;
-  afl->rand_seed[3] = afl->rand_seed[0] | 0x01abcde43f567908;
-
   if (afl->use_radamsa) {
 
     if (afl->limit_time_sig > 0) {
diff --git a/src/afl-performance.c b/src/afl-performance.c
index 8efefcd8..757bbe1e 100644
--- a/src/afl-performance.c
+++ b/src/afl-performance.c
@@ -33,6 +33,16 @@ static inline uint64_t rotl(const uint64_t x, int k) {
 
 }
 
+void rand_set_seed(afl_state_t *afl, s64 init_seed) {
+
+  afl->init_seed = init_seed;
+  afl->rand_seed[0] = hash64((void *)&afl->init_seed, sizeof(afl->init_seed), HASH_CONST);
+  afl->rand_seed[1] = afl->rand_seed[0] ^ 0x1234567890abcdef;
+  afl->rand_seed[2] = afl->rand_seed[0] & 0x0123456789abcdef;
+  afl->rand_seed[3] = afl->rand_seed[0] | 0x01abcde43f567908;
+
+}
+
 uint64_t rand_next(afl_state_t *afl) {
 
   const uint64_t result =