]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output: Fix possible null deref 6157/head
authorJeff Lucovsky <jeff@lucovsky.org>
Wed, 2 Jun 2021 11:31:20 +0000 (07:31 -0400)
committerJeff Lucovsky <jeff@lucovsky.org>
Wed, 2 Jun 2021 11:31:20 +0000 (07:31 -0400)
This commit corrects an issue uncovered by Coverity. See the redmine
issue for details: https://redmine.openinfosecfoundation.org/issues/4495

src/util-logopenfile.c

index 2e324d9d1fa7dd3efde8403bdcd2b8dc5f81826e..a68cef887de961c2c6a3e00d051f13a0d852a130 100644 (file)
@@ -328,12 +328,11 @@ bool SCLogOpenThreadedFile(
             SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate threads container");
             return false;
         }
-        if (append) {
-            parent_ctx->threads->append = SCStrdup(append);
-            if (!parent_ctx->threads->append) {
-                SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate threads append setting");
-                goto error_exit;
-            }
+
+        parent_ctx->threads->append = SCStrdup(append == NULL ? DEFAULT_LOG_MODE_APPEND : append);
+        if (!parent_ctx->threads->append) {
+            SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate threads append setting");
+            goto error_exit;
         }
 
         parent_ctx->threads->slot_count = slot_count;
@@ -344,9 +343,8 @@ bool SCLogOpenThreadedFile(
         }
         SCLogDebug("Allocated %d file context pointers for threaded array",
                     parent_ctx->threads->slot_count);
-        int slot = 1;
-        for (; slot < parent_ctx->threads->slot_count; slot++) {
-            if (!LogFileNewThreadedCtx(parent_ctx, log_path, append, slot)) {
+        for (int slot = 1; slot < parent_ctx->threads->slot_count; slot++) {
+            if (!LogFileNewThreadedCtx(parent_ctx, log_path, parent_ctx->threads->append, slot)) {
                 /* TODO: clear allocated entries [1, slot) */
                 goto error_exit;
             }