From 6ba02cac50502d1c076f400ec30409618ac951d6 Mon Sep 17 00:00:00 2001 From: Elazar Broad Date: Wed, 2 May 2018 12:38:40 -0400 Subject: [PATCH] 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. --- src/output-lua.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/output-lua.c b/src/output-lua.c index eb71ef2407..616fef018e 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, uint8_t dir) @@ -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); -- 2.47.2