about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2019-10-26 17:31:01 +0200
committerGitHub <noreply@github.com>2019-10-26 17:31:01 +0200
commit8e41a59e2e00447a97208ed7cf0d163a3d47066b (patch)
tree0091c64da66fe6238af9963f2626db578bff30bd
parent17729ce856058845314d1a3cb08e7a28d943db29 (diff)
parent15c920a6126e3a0b5ac5a7293188c3d7a523bbde (diff)
downloadafl++-8e41a59e2e00447a97208ed7cf0d163a3d47066b.tar.gz
Merge pull request #87 from devnexen/gcc_llvm_plugins_little_cjg
Little compiler plugins rework regarding block location picked up.
-rw-r--r--gcc_plugin/afl-gcc-pass.so.cc2
-rw-r--r--include/types.h12
-rw-r--r--llvm_mode/afl-llvm-pass.so.cc9
3 files changed, 22 insertions, 1 deletions
diff --git a/gcc_plugin/afl-gcc-pass.so.cc b/gcc_plugin/afl-gcc-pass.so.cc
index 633dedcb..84e02cb8 100644
--- a/gcc_plugin/afl-gcc-pass.so.cc
+++ b/gcc_plugin/afl-gcc-pass.so.cc
@@ -490,7 +490,7 @@ int plugin_init(struct plugin_name_args *  plugin_info,
   /* Setup random() so we get Actually Random(TM) outputs from R() */
   gettimeofday(&tv, &tz);
   rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
-  srandom(rand_seed);
+  SR(rand_seed);
 
   /* Pass information */
   afl_pass_info.pass = make_afl_pass(inst_ext, g);
diff --git a/include/types.h b/include/types.h
index c34bf522..3f34db66 100644
--- a/include/types.h
+++ b/include/types.h
@@ -79,9 +79,21 @@ typedef int64_t s64;
   })
 
 #ifdef AFL_LLVM_PASS
+#if defined(__linux__)
+#define AFL_SR(s) (srandom(s))
 #define AFL_R(x) (random() % (x))
 #else
+#define AFL_SR(s)
+#define AFL_R(x) (arc4random_uniform(x))
+#endif
+#else
+#if defined(__linux__)
+#define SR(s) (srandom(s))
 #define R(x) (random() % (x))
+#else
+#define SR(s)
+#define R(x) (arc4random_uniform(x))
+#endif
 #endif                                                    /* ^AFL_LLVM_PASS */
 
 #define STRINGIFY_INTERNAL(x) #x
diff --git a/llvm_mode/afl-llvm-pass.so.cc b/llvm_mode/afl-llvm-pass.so.cc
index 475a3f33..e094a0b2 100644
--- a/llvm_mode/afl-llvm-pass.so.cc
+++ b/llvm_mode/afl-llvm-pass.so.cc
@@ -34,6 +34,7 @@
 #include <list>
 #include <string>
 #include <fstream>
+#include <sys/time.h>
 
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/BasicBlock.h"
@@ -95,8 +96,16 @@ bool AFLCoverage::runOnModule(Module &M) {
 
   IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
   IntegerType *Int32Ty = IntegerType::getInt32Ty(C);
+  struct timeval            tv;
+  struct timezone           tz;
+  u32                       rand_seed;
   unsigned int cur_loc = 0;
 
+  /* Setup random() so we get Actually Random(TM) outputs from AFL_R() */
+  gettimeofday(&tv, &tz);
+  rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
+  AFL_SR(rand_seed);
+
   /* Show a banner */
 
   char be_quiet = 0;