]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
fuzz: target must use the rules it parsed
authorPhilippe Antoine <contact@catenacyber.fr>
Tue, 5 Oct 2021 18:47:30 +0000 (20:47 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 5 Oct 2021 19:32:34 +0000 (21:32 +0200)
DetectEngineReloadThreads does not work for the fuzz targets
as there is no_of_detect_tvs = 0 as we did not register
real threads and slots.

So, we force the flow worker module to use the newly detect engine
conetxt with all it needs

src/detect-engine.c
src/detect-engine.h
src/tests/fuzz/fuzz_sigpcap_aware.c

index 51bb3e25f2971ec762382511dd7b2933ede43c41..a204b1475d376da3e753c05ab87f409d65a3ff8d 100644 (file)
@@ -85,9 +85,6 @@
 
 #define DETECT_ENGINE_DEFAULT_INSPECTION_RECURSION_LIMIT 3000
 
-static DetectEngineThreadCtx *DetectEngineThreadCtxInitForReload(
-        ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt);
-
 static int DetectEngineCtxLoadConf(DetectEngineCtx *);
 
 static DetectEngineMasterCtx g_master_de_ctx = { SCMUTEX_INITIALIZER,
@@ -2835,7 +2832,7 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
  *
  * \retval det_ctx detection engine thread ctx or NULL in case of error
  */
-static DetectEngineThreadCtx *DetectEngineThreadCtxInitForReload(
+DetectEngineThreadCtx *DetectEngineThreadCtxInitForReload(
         ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt)
 {
     DetectEngineThreadCtx *det_ctx = SCMalloc(sizeof(DetectEngineThreadCtx));
index d4047e44dbb59f2a0ec312fdde5b7121ba899a8a..f952669ba8e7d782ec5da982ff7932939db50a60 100644 (file)
@@ -166,4 +166,7 @@ int DetectEngineMustParseMetadata(void);
 int WARN_UNUSED DetectBufferSetActiveList(Signature *s, const int list);
 int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s);
 
+DetectEngineThreadCtx *DetectEngineThreadCtxInitForReload(
+        ThreadVars *tv, DetectEngineCtx *new_de_ctx, int mt);
+
 #endif /* __DETECT_ENGINE_H__ */
index 3d9dcdfc5c3086701e0e81a52d9cf5fecf43c30f..2c46a098e913c06133534f2dff5fff13c681fa51 100644 (file)
@@ -138,6 +138,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
     if (DetectEngineReload(&surifuzz) < 0) {
         return 0;
     }
+    DetectEngineThreadCtx *old_det_ctx = FlowWorkerGetDetectCtxPtr(fwd);
+
+    DetectEngineCtx *de_ctx = DetectEngineGetCurrent();
+    de_ctx->ref_cnt--;
+    DetectEngineThreadCtx *new_det_ctx = DetectEngineThreadCtxInitForReload(&tv, de_ctx, 1);
+    FlowWorkerReplaceDetectCtx(fwd, new_det_ctx);
+
+    DetectEngineThreadCtxDeinit(NULL, old_det_ctx);
 
     // loop over packets
     r = FPC_next(&pkts, &header, &pkt);