]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: add de_state duplication check
authorVictor Julien <victor@inliniac.net>
Wed, 25 Mar 2015 08:19:49 +0000 (09:19 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 11 May 2015 10:55:26 +0000 (12:55 +0200)
Add test to check if no duplicate destate is created.

Only enabled with DEBUG_VALIDATION.

src/detect-engine-state.c

index 9e5f4d5173e08beb5fe10f3ad3a291ae5aaac71b..8cbc5b85404da4dd7d1a922ef166280230cf0b9c 100644 (file)
@@ -124,11 +124,42 @@ static DeStateStoreFlowRules *DeStateStoreFlowRulesAlloc(void)
     return d;
 }
 
+#ifdef DEBUG_VALIDATION
+static int DeStateSearchState(DetectEngineState *state, uint8_t direction, SigIntId num)
+{
+    DetectEngineStateDirection *dir_state = &state->dir_state[direction & STREAM_TOSERVER ? 0 : 1];
+    DeStateStore *tx_store = dir_state->head;
+    SigIntId store_cnt;
+    SigIntId state_cnt = 0;
+
+    for (; tx_store != NULL; tx_store = tx_store->next) {
+        SCLogDebug("tx_store %p", tx_store);
+        for (store_cnt = 0;
+             store_cnt < DE_STATE_CHUNK_SIZE && state_cnt < dir_state->cnt;
+             store_cnt++, state_cnt++)
+        {
+            DeStateStoreItem *item = &tx_store->store[store_cnt];
+            if (item->sid == num) {
+                SCLogDebug("BUG! sid %u already in state: %p %p %p %u %u, direction %s",
+                            num, state, dir_state, tx_store, state_cnt,
+                            store_cnt, direction & STREAM_TOSERVER ? "toserver" : "toclient");
+                return 1;
+            }
+        }
+    }
+    return 0;
+}
+#endif
+
 static void DeStateSignatureAppend(DetectEngineState *state, Signature *s, uint32_t inspect_flags, uint8_t direction)
 {
     int jump = 0;
     int i = 0;
     DetectEngineStateDirection *dir_state = &state->dir_state[direction & STREAM_TOSERVER ? 0 : 1];
+
+#ifdef DEBUG_VALIDATION
+    BUG_ON(DeStateSearchState(state, direction, s->num));
+#endif
     DeStateStore *store = dir_state->head;
 
     if (store == NULL) {