]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
eve/mqtt: fix mqtt logging with threaded eve 6016/head
authorJason Ish <jason.ish@oisf.net>
Thu, 25 Mar 2021 18:11:01 +0000 (12:11 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Apr 2021 11:26:57 +0000 (13:26 +0200)
Mqtt was not setting up a per-thread file context for logging
in threaded mode, leading a crash when used in threaded mode.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/4404

(cherry picked from commit 64330498f842386cc1f1cdec0409959b5565496f)

src/output-json-mqtt.c

index 8a19a436f4730cc9a01f428cc18f44ce1c9db844..811024960fd6308f05cfdbe181d54e29e715e8c3 100644 (file)
@@ -58,6 +58,7 @@ typedef struct LogMQTTLogThread_ {
     LogMQTTFileCtx *mqttlog_ctx;
     uint32_t        count;
     MemBuffer      *buffer;
+    LogFileCtx *file_ctx;
 } LogMQTTLogThread;
 
 bool JsonMQTTAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
@@ -94,7 +95,7 @@ static int JsonMQTTLogger(ThreadVars *tv, void *thread_data,
         goto error;
 
     MemBufferReset(thread->buffer);
-    OutputJsonBuilderBuffer(js, thread->mqttlog_ctx->file_ctx, &thread->buffer);
+    OutputJsonBuilderBuffer(js, thread->file_ctx, &thread->buffer);
     jb_free(js);
 
     return TM_ECODE_OK;
@@ -174,6 +175,8 @@ static TmEcode JsonMQTTLogThreadInit(ThreadVars *t, const void *initdata, void *
     }
 
     thread->mqttlog_ctx = ((OutputCtx *)initdata)->data;
+    thread->file_ctx = LogFileEnsureExists(thread->mqttlog_ctx->file_ctx, t->id);
+
     *data = (void *)thread;
 
     return TM_ECODE_OK;