]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
qa: add --no-random commandline option
authorVictor Julien <victor@inliniac.net>
Sat, 15 Apr 2017 16:58:31 +0000 (18:58 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Apr 2017 14:03:32 +0000 (16:03 +0200)
src/app-layer-htp.c
src/defrag-hash.c
src/flow.c
src/host.c
src/ippair.c
src/suricata.c
src/suricata.h
src/util-random.c

index 1f0cece872049ea2daeafb0eb20ed200fdac9143..5b8e61c25f2f109099584385db600eac2801a9c1 100644 (file)
@@ -2149,11 +2149,12 @@ static void HTPConfigSetDefaultsPhase1(HTPCfgRec *cfg_prec)
     cfg_prec->request.inspect_window = HTP_CONFIG_DEFAULT_REQUEST_INSPECT_WINDOW;
     cfg_prec->response.inspect_min_size = HTP_CONFIG_DEFAULT_RESPONSE_INSPECT_MIN_SIZE;
     cfg_prec->response.inspect_window = HTP_CONFIG_DEFAULT_RESPONSE_INSPECT_WINDOW;
-#ifndef AFLFUZZ_NO_RANDOM
-    cfg_prec->randomize = HTP_CONFIG_DEFAULT_RANDOMIZE;
-#else
-    cfg_prec->randomize = 0;
-#endif
+
+    if (!g_disable_randomness) {
+        cfg_prec->randomize = HTP_CONFIG_DEFAULT_RANDOMIZE;
+    } else {
+        cfg_prec->randomize = 0;
+    }
     cfg_prec->randomize_range = HTP_CONFIG_DEFAULT_RANDOMIZE_RANGE;
 
     htp_config_register_request_header_data(cfg_prec->cfg, HTPCallbackRequestHeaderData);
@@ -2471,9 +2472,9 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s,
                     (size_t)HTP_CONFIG_DEFAULT_FIELD_LIMIT_SOFT,
                     (size_t)limit);
         } else if (strcasecmp("randomize-inspection-sizes", p->name) == 0) {
-#ifndef AFLFUZZ_NO_RANDOM
-            cfg_prec->randomize = ConfValIsTrue(p->val);
-#endif
+            if (!g_disable_randomness) {
+                cfg_prec->randomize = ConfValIsTrue(p->val);
+            }
         } else if (strcasecmp("randomize-inspection-range", p->name) == 0) {
             uint32_t range = atoi(p->val);
             if (range > 100) {
index 6203baa28d9397a84147e6b79581a032c0a193cf..9087f26aceba41cc97d366b2b5e71513638f64e5 100644 (file)
@@ -133,10 +133,8 @@ void DefragInitConfig(char quiet)
     SC_ATOMIC_INIT(defragtracker_prune_idx);
     DefragTrackerQueueInit(&defragtracker_spare_q);
 
-#ifndef AFLFUZZ_NO_RANDOM
     /* set defaults */
     defrag_config.hash_rand   = (uint32_t)RandomGet();
-#endif
     defrag_config.hash_size   = DEFRAG_DEFAULT_HASHSIZE;
     defrag_config.memcap      = DEFRAG_DEFAULT_MEMCAP;
     defrag_config.prealloc    = DEFRAG_DEFAULT_PREALLOC;
index 8512e954ec4cb631eca06b2b6fd1e35a651cd18a..6d199f776450792e65ce0b9e886052956825e733 100644 (file)
@@ -349,10 +349,8 @@ void FlowInitConfig(char quiet)
     FlowQueueInit(&flow_spare_q);
     FlowQueueInit(&flow_recycle_q);
 
-#ifndef AFLFUZZ_NO_RANDOM
     /* set defaults */
     flow_config.hash_rand   = (uint32_t)RandomGet();
-#endif
     flow_config.hash_size   = FLOW_DEFAULT_HASHSIZE;
     flow_config.memcap      = FLOW_DEFAULT_MEMCAP;
     flow_config.prealloc    = FLOW_DEFAULT_PREALLOC;
index 2e9061cc7d485a825f21e900995ff30d515aa646..11a4ca8d4d8b3e130968a128f1116ff424de163b 100644 (file)
@@ -141,10 +141,8 @@ void HostInitConfig(char quiet)
     SC_ATOMIC_INIT(host_prune_idx);
     HostQueueInit(&host_spare_q);
 
-#ifndef AFLFUZZ_NO_RANDOM
     /* set defaults */
     host_config.hash_rand   = (uint32_t)RandomGet();
-#endif
     host_config.hash_size   = HOST_DEFAULT_HASHSIZE;
     host_config.memcap      = HOST_DEFAULT_MEMCAP;
     host_config.prealloc    = HOST_DEFAULT_PREALLOC;
index 66fce1e5a56127da7eb39d3e0c634db0e1b8a613..5c35efa47597c068366e85be2444995ac4652814 100644 (file)
@@ -137,10 +137,8 @@ void IPPairInitConfig(char quiet)
     SC_ATOMIC_INIT(ippair_prune_idx);
     IPPairQueueInit(&ippair_spare_q);
 
-#ifndef AFLFUZZ_NO_RANDOM
     /* set defaults */
     ippair_config.hash_rand   = (uint32_t)RandomGet();
-#endif
     ippair_config.hash_size   = IPPAIR_DEFAULT_HASHSIZE;
     ippair_config.memcap      = IPPAIR_DEFAULT_MEMCAP;
     ippair_config.prealloc    = IPPAIR_DEFAULT_PREALLOC;
index 6cd05f2c8a7005ee72ac0bcfce1266993f6e5782..27aa0b47f502a4189b5ae47b987b345c42cc5935 100644 (file)
@@ -220,6 +220,13 @@ int sc_set_caps = FALSE;
 /** highest mtu of the interfaces we monitor */
 int g_default_mtu = 0;
 
+/** disable randomness to get reproducible results accross runs */
+#ifndef AFLFUZZ_NO_RANDOM
+int g_disable_randomness = 0;
+#else
+int g_disable_randomness = 1;
+#endif
+
 int EngineModeIsIPS(void)
 {
     return (g_engine_mode == ENGINE_MODE_IPS);
@@ -1461,6 +1468,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
         {"netmap", optional_argument, 0, 0},
         {"pcap", optional_argument, 0, 0},
         {"simulate-ips", 0, 0 , 0},
+        {"no-random", 0, &g_disable_randomness, 1},
 
         /* AFL app-layer options. */
         {"afl-http-request", required_argument, 0 , 0},
index aaee9fe535e2d1f4b24b4aad18229b726787068a..c49b7f43a0fedcca9fa79114582a80b50b8ffe8e 100644 (file)
@@ -172,6 +172,7 @@ typedef struct SCInstance_ {
 void GlobalsInitPreConfig();
 
 extern volatile uint8_t suricata_ctl_flags;
+extern int g_disable_randomness;
 
 /* uppercase to lowercase conversion lookup table */
 uint8_t g_u8_lowercasetable[256];
index 17bd74baedc2a2137868a4d4efa79795fed8f499..08916ec4943396aec9aba4d508329b0bb172a6a1 100644 (file)
@@ -31,6 +31,9 @@
 
 long int RandomGet(void)
 {
+    if (g_disable_randomness)
+        return 0;
+
     HCRYPTPROV p;
     if (!(CryptAcquireContext(&p, NULL, NULL,
                 PROV_RSA_FULL, 0))) {
@@ -50,6 +53,9 @@ long int RandomGet(void)
 #elif defined(HAVE_CLOCK_GETTIME)
 long int RandomGet(void)
 {
+    if (g_disable_randomness)
+        return 0;
+
     struct timespec ts;
     clock_gettime(CLOCK_REALTIME, &ts);
 
@@ -60,6 +66,9 @@ long int RandomGet(void)
 #else
 long int RandomGet(void)
 {
+    if (g_disable_randomness)
+        return 0;
+
     struct timeval tv;
     memset(&tv, 0, sizeof(tv));
     gettimeofday(&tv, NULL);