From 26d6410d167b7a33df96949164aeb98117f1b408 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 7 Aug 2026 08:04:15 +0000 Subject: [PATCH] log/tcp-data: replace BUG_ON with graceful error handling Replace the BUG_ON with proper error handling so that any fopen() failure logs a warning and skips the chunk instead of causing a crash. Adds a few more warnings for error conditions. Ticket: #8823. --- src/log-tcp-data.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/log-tcp-data.c b/src/log-tcp-data.c index 48df343928..bb05c40344 100644 --- a/src/log-tcp-data.c +++ b/src/log-tcp-data.c @@ -103,12 +103,19 @@ static int LogTcpDataLoggerDir(ThreadVars *tv, void *thread_data, const Flow *f, flags & OUTPUT_STREAMING_FLAG_TOSERVER ? "ts" : "tc"); FILE *fp = fopen(name, mode); - BUG_ON(fp == NULL); + if (fp == NULL) { + SCLogWarning("failed to open '%s': %s", name, strerror(errno)); + SCReturnInt(TM_ECODE_OK); + } // PrintRawDataFp(stdout, (uint8_t *)data, data_len); - fwrite(data, data_len, 1, fp); + if (fwrite(data, data_len, 1, fp) != 1) { + SCLogWarning("write to '%s' failed: %s", name, strerror(errno)); + } - fclose(fp); + if (fclose(fp) != 0) { + SCLogWarning("failed to close '%s': %s", name, strerror(errno)); + } } SCReturnInt(TM_ECODE_OK); } @@ -281,8 +288,13 @@ OutputInitResult LogTcpDataLogInitCtx(SCConfNode *conf) SCLogInfo("using directory %s", dirfull); - /* if mkdir fails file open will fail, so deal with errors there */ - (void)SCMkDir(dirfull, 0700); + if (SCMkDir(dirfull, 0700) < 0 && errno != EEXIST) { + SCLogError("failed to create log directory '%s': %s", dirfull, strerror(errno)); + LogFileFreeCtx(file_ctx); + SCFree(tcpdatalog_ctx); + result = (OutputInitResult){ NULL, false }; + return result; + } } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));