From: Elazar Broad Date: Wed, 2 May 2018 16:38:40 +0000 (-0400) Subject: Fix segfault when the protocol is anything other than HTTP X-Git-Tag: suricata-4.0.5~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=554ddab3308a43008893bfb1706855ee70b311c2;p=thirdparty%2Fsuricata.git Fix segfault when the protocol is anything other than HTTP 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. --- diff --git a/src/output-lua.c b/src/output-lua.c index 6d7d7a07b7..77059fc5b8 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -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);