From: Maxtors Date: Mon, 1 Feb 2016 13:54:29 +0000 (+0100) Subject: Added checking of negated "totals" and "threads" config values for stats. X-Git-Tag: suricata-3.0.1RC1~157 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b8bd9dfc9fb99162233983e7c3c97f3ec7684da;p=thirdparty%2Fsuricata.git Added checking of negated "totals" and "threads" config values for stats. --- diff --git a/src/log-stats.c b/src/log-stats.c index 385dec2bb4..8507deb301 100644 --- a/src/log-stats.c +++ b/src/log-stats.c @@ -245,6 +245,15 @@ OutputCtx *LogStatsLogInitCtx(ConfNode *conf) const char *nulls = ConfNodeLookupChildValue(conf, "null-values"); SCLogDebug("totals %s threads %s", totals, threads); + if ((totals != NULL && ConfValIsFalse(totals)) && + (threads != NULL && ConfValIsFalse(threads))) { + LogFileFreeCtx(file_ctx); + SCFree(statslog_ctx); + SCLogError(SC_ERR_STATS_LOG_NEGATED, + "Cannot disable both totals and threads in stats logging"); + return NULL; + } + if (totals != NULL && ConfValIsFalse(totals)) { statslog_ctx->flags &= ~LOG_STATS_TOTALS; } diff --git a/src/output-json-stats.c b/src/output-json-stats.c index fea7177aa8..a22f9d6b96 100644 --- a/src/output-json-stats.c +++ b/src/output-json-stats.c @@ -327,6 +327,14 @@ OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx) const char *deltas = ConfNodeLookupChildValue(conf, "deltas"); SCLogDebug("totals %s threads %s deltas %s", totals, threads, deltas); + if ((totals != NULL && ConfValIsFalse(totals)) && + (threads != NULL && ConfValIsFalse(threads))) { + SCFree(stats_ctx); + SCLogError(SC_ERR_JSON_STATS_LOG_NEGATED, + "Cannot disable both totals and threads in stats logging"); + return NULL; + } + if (totals != NULL && ConfValIsFalse(totals)) { stats_ctx->flags &= ~JSON_STATS_TOTALS; } diff --git a/src/util-error.c b/src/util-error.c index 7f2caf00d2..8ea229b598 100644 --- a/src/util-error.c +++ b/src/util-error.c @@ -312,6 +312,8 @@ const char * SCErrorToString(SCError err) CASE_CODE (SC_ERR_MT_NO_MAPPING); CASE_CODE (SC_ERR_NO_JSON_SUPPORT); CASE_CODE (SC_ERR_INVALID_RULE_ARGUMENT); + CASE_CODE (SC_ERR_STATS_LOG_NEGATED); + CASE_CODE (SC_ERR_JSON_STATS_LOG_NEGATED); } return "UNKNOWN_ERROR"; diff --git a/src/util-error.h b/src/util-error.h index cd2ce24927..fec09d04a7 100644 --- a/src/util-error.h +++ b/src/util-error.h @@ -302,6 +302,8 @@ typedef enum { SC_ERR_INVALID_RULE_ARGUMENT, /**< Generic error code for invalid * rule argument. */ SC_ERR_MT_NO_MAPPING, + SC_ERR_STATS_LOG_NEGATED, /** When totals and threads are both NO in yaml **/ + SC_ERR_JSON_STATS_LOG_NEGATED, /** When totals and threads are both NO in yaml **/ } SCError; const char *SCErrorToString(SCError);