From 02fe0260462c708a31f4bb955f4ffe0b0dadd692 Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Wed, 2 Jun 2021 07:31:20 -0400 Subject: [PATCH] output: Fix possible null deref This commit corrects an issue uncovered by Coverity. See the redmine issue for details: https://redmine.openinfosecfoundation.org/issues/4495 --- src/util-logopenfile.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 2e324d9d1f..a68cef887d 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -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; }