From a0bb4477db15c2820affa003ab80f2e8396ec33c Mon Sep 17 00:00:00 2001 From: Alexander Gozman Date: Fri, 18 Jul 2014 20:36:12 +0400 Subject: [PATCH] Fix possible crash when logfile descriptor is invalid --- src/util-logopenfile.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 86e61db7cc..6d0a25deac 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -81,8 +81,12 @@ static int SCLogFileWrite(const char *buffer, int buffer_len, LogFileCtx *log_ct SCConfLogReopen(log_ctx); } - int ret = fwrite(buffer, buffer_len, 1, log_ctx->fp); - fflush(log_ctx->fp); + int ret = 0; + + if (log_ctx->fp) { + ret = fwrite(buffer, buffer_len, 1, log_ctx->fp); + fflush(log_ctx->fp); + } return ret; } -- 2.47.3