]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output/email: use SCCalloc for OutputJsonEmailCtx
authorShivani Bhardwaj <shivani@oisf.net>
Wed, 4 Oct 2023 07:44:41 +0000 (13:14 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 6 Oct 2023 19:28:14 +0000 (21:28 +0200)
email_ctx->fields only gets populated when smtp.custom setting is on.
The fn EveEmailLogJSONCustom is called when either
1. smtp.extended setting is on or,
2. email_ctx->fields is populated which means smtp.custom setting is on

In case neither of these are set in suricata.yaml, no call should
ideally be made to the fn EveEmailLogJSONCustom.
However, it turns out that email_ctx->fields is unset and then set only
after the smtp config was found. This leads to email_ctx->fields
sometimes contain value even when no config was given to the smtp
section and can lead to unexpected output.

Fix this by using SCCalloc while initializing OutputJsonEmailCtx struct
instead of SCMalloc.

Bug 6380

src/output-json-smtp.c

index cc300390758599cc156a7c765eab8377e65bb6c8..f7674687c5c403a3d1d5cdb5cd3dbe0941bd3b3f 100644 (file)
@@ -122,7 +122,7 @@ static OutputInitResult OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_c
     OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
-    OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
+    OutputJsonEmailCtx *email_ctx = SCCalloc(1, sizeof(OutputJsonEmailCtx));
     if (unlikely(email_ctx == NULL))
         return result;