]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix segfault when the protocol is anything other than HTTP
authorElazar Broad <elazar@thebroadfamily.com>
Wed, 2 May 2018 16:38:40 +0000 (12:38 -0400)
committerVictor Julien <victor@inliniac.net>
Mon, 16 Jul 2018 11:30:49 +0000 (13:30 +0200)
When a file is transferred over anything other than HTTP, the previously hard-coded HTTP protocol would trigger a non-existent index into htp_list_array_get(), causing a segfault. This patch mimics the logic in detect-lua-extensions.c.

src/output-lua.c

index 6d7d7a07b76d765f4e71098bba9bf22ded0610ff..77059fc5b850169cbe8c19d8708c7b7423689c9c 100644 (file)
@@ -303,8 +303,6 @@ static int LuaPacketCondition(ThreadVars *tv, const Packet *p)
  *
  *  Executes a script once for one file.
  *
- * TODO non-http support
- *
  * NOTE p->flow is locked at this point
  */
 static int LuaFileLogger(ThreadVars *tv, void *thread_data, const Packet *p, const File *ff)
@@ -319,17 +317,16 @@ static int LuaFileLogger(ThreadVars *tv, void *thread_data, const Packet *p, con
 
     SCLogDebug("ff %p", ff);
 
-    /* Get the TX so the script can get more context about it.
-     * TODO hardcoded to HTTP currently */
-    void *txptr = NULL;
-    if (p->flow && p->flow->alstate)
-        txptr = AppLayerParserGetTx(p->proto, ALPROTO_HTTP, p->flow->alstate, ff->txid);
-
     SCMutexLock(&td->lua_ctx->m);
 
     LuaStateSetThreadVars(td->lua_ctx->luastate, tv);
     LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p);
-    LuaStateSetTX(td->lua_ctx->luastate, txptr);
+    if (p->flow && p->flow->alstate) {
+        void *txptr = AppLayerParserGetTx(p->proto, p->flow->alproto, p->flow->alstate, ff->txid);
+        if (txptr) {
+            LuaStateSetTX(td->lua_ctx->luastate, txptr);
+        }
+    }
     LuaStateSetFlow(td->lua_ctx->luastate, p->flow);
     LuaStateSetFile(td->lua_ctx->luastate, (File *)ff);