From: Victor Julien Date: Wed, 25 Mar 2015 08:19:49 +0000 (+0100) Subject: detect: add de_state duplication check X-Git-Tag: suricata-3.0RC1~435 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc6e4140befa80080777c41040eb47f9b6e05129;p=thirdparty%2Fsuricata.git detect: add de_state duplication check Add test to check if no duplicate destate is created. Only enabled with DEBUG_VALIDATION. --- diff --git a/src/detect-engine-state.c b/src/detect-engine-state.c index 9e5f4d5173..8cbc5b8540 100644 --- a/src/detect-engine-state.c +++ b/src/detect-engine-state.c @@ -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) {