]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
afl: add define to disable rand_r use
authorVictor Julien <victor@inliniac.net>
Sat, 5 Dec 2015 13:14:58 +0000 (14:14 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 12 Apr 2016 13:19:59 +0000 (15:19 +0200)
The randomness affects AFL. It creates variable test cases, which
we need to avoid.

src/defrag-hash.c
src/flow.c
src/host.c
src/ippair.c
src/suricata-common.h

index e37a08738d85bb433d58f46e93dd3b2f671b5419..284b582f6e7323361036693a1c88eceb0deb2933 100644 (file)
@@ -132,10 +132,11 @@ void DefragInitConfig(char quiet)
     SC_ATOMIC_INIT(defragtracker_prune_idx);
     DefragTrackerQueueInit(&defragtracker_spare_q);
 
+#ifndef AFLFUZZ_NO_RANDOM
     unsigned int seed = RandomTimePreseed();
     /* set defaults */
     defrag_config.hash_rand   = (int)(DEFRAG_DEFAULT_HASHSIZE * (rand_r(&seed) / RAND_MAX + 1.0));
-
+#endif
     defrag_config.hash_size   = DEFRAG_DEFAULT_HASHSIZE;
     defrag_config.memcap      = DEFRAG_DEFAULT_MEMCAP;
     defrag_config.prealloc    = DEFRAG_DEFAULT_PREALLOC;
index fa8b21ba958782b24f1a77efeed9abac17640ec0..4cedf2685db9ad042e05f5081c6315046ad0f6eb 100644 (file)
@@ -355,10 +355,11 @@ void FlowInitConfig(char quiet)
     FlowQueueInit(&flow_spare_q);
     FlowQueueInit(&flow_recycle_q);
 
+#ifndef AFLFUZZ_NO_RANDOM
     unsigned int seed = RandomTimePreseed();
     /* set defaults */
     flow_config.hash_rand   = (int)( FLOW_DEFAULT_HASHSIZE * (rand_r(&seed) / RAND_MAX + 1.0));
-
+#endif
     flow_config.hash_size   = FLOW_DEFAULT_HASHSIZE;
     flow_config.memcap      = FLOW_DEFAULT_MEMCAP;
     flow_config.prealloc    = FLOW_DEFAULT_PREALLOC;
index a28639cce45480eb904823761ef4a2d0135f0b9a..faf9513bde87dab58bc8433ac93f8b8eaf4287b3 100644 (file)
@@ -141,10 +141,11 @@ void HostInitConfig(char quiet)
     SC_ATOMIC_INIT(host_prune_idx);
     HostQueueInit(&host_spare_q);
 
+#ifndef AFLFUZZ_NO_RANDOM
     unsigned int seed = RandomTimePreseed();
     /* set defaults */
     host_config.hash_rand   = (int)( HOST_DEFAULT_HASHSIZE * (rand_r(&seed) / RAND_MAX + 1.0));
-
+#endif
     host_config.hash_size   = HOST_DEFAULT_HASHSIZE;
     host_config.memcap      = HOST_DEFAULT_MEMCAP;
     host_config.prealloc    = HOST_DEFAULT_PREALLOC;
index 79ecb76ca8064022d83686efcb56c21d67fbd5f5..736cdce5bad50a963b5dfc09bfe54d9f97af470b 100644 (file)
@@ -137,10 +137,11 @@ void IPPairInitConfig(char quiet)
     SC_ATOMIC_INIT(ippair_prune_idx);
     IPPairQueueInit(&ippair_spare_q);
 
+#ifndef AFLFUZZ_NO_RANDOM
     unsigned int seed = RandomTimePreseed();
     /* set defaults */
     ippair_config.hash_rand   = (int)( IPPAIR_DEFAULT_HASHSIZE * (rand_r(&seed) / RAND_MAX + 1.0));
-
+#endif
     ippair_config.hash_size   = IPPAIR_DEFAULT_HASHSIZE;
     ippair_config.memcap      = IPPAIR_DEFAULT_MEMCAP;
     ippair_config.prealloc    = IPPAIR_DEFAULT_PREALLOC;
index 18791c3b04bcd59537082e121dcf842e7e16c134..4910c4185d7c5592aef72b3b363b6bd78a88c443 100644 (file)
 #endif
 #endif
 
+#define AFLFUZZ_NO_RANDOM 1
+
 /* we need this to stringify the defines which are supplied at compiletime see:
    http://gcc.gnu.org/onlinedocs/gcc-3.4.1/cpp/Stringification.html#Stringification */
 #define xstr(s) str(s)