]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: don't error out on no de_ctx
authorVictor Julien <victor@inliniac.net>
Thu, 12 Feb 2015 13:13:46 +0000 (14:13 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 23 Jul 2015 17:36:15 +0000 (19:36 +0200)
This can happen on a multi-detect setup with no registered
engines yet.

src/detect.c

index 56dab7907bfe356019104bc0bec778cc412518e2..19f0da699a46bf67d4ddc909f815cc1e9770b37f 100644 (file)
@@ -1964,6 +1964,7 @@ TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQue
         return 0;
     }
 
+    DetectEngineCtx *de_ctx = NULL;
     DetectEngineThreadCtx *det_ctx = (DetectEngineThreadCtx *)data;
     if (det_ctx == NULL) {
         printf("ERROR: Detect has no thread ctx\n");
@@ -1976,20 +1977,21 @@ TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQue
                   det_ctx);
     }
 
-    DetectEngineCtx *de_ctx = det_ctx->de_ctx;
-
     if (det_ctx->TenantGetId != NULL) {
+        /* in MT mode, but no tenants registered yet */
         if (det_ctx->mt_det_ctxs == 0) {
-            printf("ERROR: Detect has no detection engine ctx\n");
-            goto error;
+            return TM_ECODE_OK;
         }
 
         uint32_t tenant_id = det_ctx->TenantGetId(det_ctx, p);
         if (tenant_id > 0 && tenant_id < det_ctx->mt_det_ctxs_cnt) {
             det_ctx = det_ctx->mt_det_ctxs[tenant_id];
-            BUG_ON(det_ctx == NULL);
+            if (det_ctx == NULL)
+                return TM_ECODE_OK;
             de_ctx = det_ctx->de_ctx;
-            BUG_ON(de_ctx == NULL);
+            if (de_ctx == NULL)
+                return TM_ECODE_OK;
+
             if (SC_ATOMIC_GET(det_ctx->so_far_used_by_detect) == 0) {
                 (void)SC_ATOMIC_SET(det_ctx->so_far_used_by_detect, 1);
                 SCLogDebug("MT de_ctx %p det_ctx %p (tenant %u)", de_ctx, det_ctx, tenant_id);
@@ -1997,6 +1999,8 @@ TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQue
         } else {
             return TM_ECODE_OK;
         }
+    } else {
+        de_ctx = det_ctx->de_ctx;
     }
 
     /* see if the packet matches one or more of the sigs */