]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix luajit compilation failure introduced by the transaction update. 370/head
authorAnoop Saldanha <anoopsaldanha@gmail.com>
Fri, 17 May 2013 10:51:54 +0000 (16:21 +0530)
committerAnoop Saldanha <anoopsaldanha@gmail.com>
Fri, 17 May 2013 18:21:21 +0000 (23:51 +0530)
Fix coverity lock issues reported by transaction update as well.

src/app-layer-parser.c
src/detect-engine-state.c
src/detect-luajit.c

index e4cb52def087e84924ad14a21e2745cbd6492b2a..404aa41b3798bb071acd1dfc8b7a0f94ab00f940 100644 (file)
@@ -1154,7 +1154,9 @@ void AppLayerTransactionUpdateInspectId(Flow *f, uint8_t flags)
 
     ((AppLayerParserStateStore *)f->alparser)->inspect_id[direction] = idx;
     if (tx_updated_by > 0) {
+        SCMutexLock(&f->de_state_m);
         DetectEngineStateReset(f->de_state, flags);
+        SCMutexUnlock(&f->de_state_m);
     }
 
     return;
index 8f2b2d70f0a48cec5d909c2358a1a385045e3eec..247bb8bee8b9b56485c499c025170e569bed08f2 100644 (file)
@@ -416,6 +416,7 @@ void DeStateDetectContinueDetection(ThreadVars *tv, DetectEngineCtx *de_ctx,
 
     DetectEngineStateDirection *dir_state = &f->de_state->dir_state[flags & STREAM_TOSERVER ? 0 : 1];
     DeStateStore *store = dir_state->head;
+    void *inspect_tx = NULL;
     uint64_t inspect_tx_id = 0;
     uint64_t total_txs = 0;
     uint8_t alproto_supports_txs = 0;
@@ -423,8 +424,10 @@ void DeStateDetectContinueDetection(ThreadVars *tv, DetectEngineCtx *de_ctx,
     DeStateResetFileInspection(f, alproto, alstate, flags);
 
     if (AppLayerAlprotoSupportsTxs(alproto)) {
+        FLOWLOCK_RDLOCK(f);
         inspect_tx_id = AppLayerTransactionGetInspectId(f, flags);
         total_txs = AppLayerGetTxCnt(alproto, alstate);
+        FLOWLOCK_UNLOCK(f);
         alproto_supports_txs = 1;
     }
 
@@ -505,11 +508,9 @@ void DeStateDetectContinueDetection(ThreadVars *tv, DetectEngineCtx *de_ctx,
                 }
 
                 engine = app_inspection_engine[alproto][(flags & STREAM_TOSERVER) ? 0 : 1];
-                void *inspect_tx = AppLayerGetTx(alproto, alstate, inspect_tx_id);
-                if (inspect_tx == NULL) {
-                    FLOWLOCK_UNLOCK(f);
-                    goto end;
-                }
+                inspect_tx = AppLayerGetTx(alproto, alstate, inspect_tx_id);
+                if (inspect_tx == NULL)
+                    continue;
                 while (engine != NULL) {
                     if (!(item->flags & engine->inspect_flags) &&
                         s->sm_lists[engine->sm_list] != NULL)
index d5cbd64ac56b87afb12278394f5d421e8925cc44..866a4a6da8d5fd50e085d50585fcbd7842f06791 100644 (file)
@@ -48,6 +48,7 @@
 #include "util-unittest-helper.h"
 
 #include "app-layer.h"
+#include "app-layer-parser.h"
 
 #include "stream-tcp.h"
 
@@ -380,25 +381,21 @@ static int DetectLuajitMatch (ThreadVars *tv, DetectEngineThreadCtx *det_ctx,
         FLOWLOCK_RDLOCK(p->flow);
         HtpState *htp_state = p->flow->alstate;
         if (htp_state != NULL && htp_state->connp != NULL && htp_state->connp->conn != NULL) {
-            uint64_t idx = AppLayerTransactionGetInspectId(p->flow, flags);
-            if (idx != -1) {
-                htp_tx_t *tx = NULL;
-
-                uint64_t total_txs= AppLayerGetNoOfTxs(ALPROTO_HTTP, htp_state);
-                for ( ; idx < size; idx++)
-                {
-                    tx = AppLayerGetTx(http_state, idx);
-                    if (tx == NULL)
-                        continue;
-
-                    if ((tluajit->flags & DATATYPE_HTTP_REQUEST_LINE) && tx->request_line != NULL &&
-                            bstr_len(tx->request_line) > 0) {
-                        lua_pushliteral(tluajit->luastate, "http.request_line"); /* stack at -2 */
-                        lua_pushlstring (tluajit->luastate,
-                                (const char *)bstr_ptr(tx->request_line),
-                                bstr_len(tx->request_line));
-                        lua_settable(tluajit->luastate, -3);
-                    }
+            htp_tx_t *tx = NULL;
+            uint64_t idx = AppLayerTransactionGetInspectId(p->flow, 0);
+            uint64_t total_txs= AppLayerGetTxCnt(ALPROTO_HTTP, htp_state);
+            for ( ; idx < total_txs; idx++) {
+                tx = AppLayerGetTx(ALPROTO_HTTP, htp_state, idx);
+                if (tx == NULL)
+                    continue;
+
+                if ((tluajit->flags & DATATYPE_HTTP_REQUEST_LINE) && tx->request_line != NULL &&
+                    bstr_len(tx->request_line) > 0) {
+                    lua_pushliteral(tluajit->luastate, "http.request_line"); /* stack at -2 */
+                    lua_pushlstring (tluajit->luastate,
+                                     (const char *)bstr_ptr(tx->request_line),
+                                     bstr_len(tx->request_line));
+                    lua_settable(tluajit->luastate, -3);
                 }
             }
         }