]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3485: Fix config logger
authorSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 5 Jul 2022 14:21:52 +0000 (14:21 +0000)
committerSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 5 Jul 2022 14:21:52 +0000 (14:21 +0000)
Merge in SNORT/snort3 from ~VHORBAN/snort3:fix_config_logger to master

Squashed commit of the following:

commit 4ce90eea0b6b7c75f4321c3cabdc6781178291a9
Author: Oleksandr Serhiienko <oserhiie@cisco.com>
Date:   Wed Jun 15 17:21:26 2022 +0300

    build: remove unnecessary type casts

commit 6cda44321578d31de30524a5b8a50ce7713ecea9
Author: Oleksandr Serhiienko <oserhiie@cisco.com>
Date:   Wed Jun 15 17:02:52 2022 +0300

    log: add log_value and log_limit overloads with built-in integer types

        Using built-in integer types in overloads of ConfigLogger::log_value
        and ConfigLogger::log_limit resolves possible ambiguity over different
        platforms in case of platform-dependent integer types like size_t

src/log/messages.cc
src/log/messages.h
src/network_inspectors/appid/appid_config.cc
src/network_inspectors/perf_monitor/perf_monitor.cc
src/network_inspectors/port_scan/port_scan.cc
src/service_inspectors/http_inspect/http_inspect.cc
src/service_inspectors/netflow/netflow.cc

index e621259fdb6e9a93e7749dd164c78a364cc9135e..a0eee8999967d81312b1c3d90b23f194a1cfb7cf 100644 (file)
@@ -342,9 +342,76 @@ bool ConfigLogger::log_flag(const char* caption, bool flag, bool subopt)
     return flag;
 }
 
+void ConfigLogger::log_limit(const char* caption, int val, int unlim, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRId32 "%s\n" : CAPTION "%" PRId32 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == unlim )
+        LogMessage(fmt, ind, caption, val, " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, val, "");
+}
+
+void ConfigLogger::log_limit(const char* caption, unsigned int val, unsigned int unlim, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu32 "%s\n" : CAPTION "%" PRIu32 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == unlim )
+        LogMessage(fmt, ind, caption, val, " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, val, "");
+}
+
+void ConfigLogger::log_limit(const char* caption, long val, int unlim, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRId64 "%s\n" : CAPTION "%" PRId64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == unlim )
+        LogMessage(fmt, ind, caption, static_cast<long long>(val), " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, static_cast<long long>(val), "");
+}
+
+void ConfigLogger::log_limit(const char* caption, unsigned long val, unsigned int unlim, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu64 "%s\n" : CAPTION "%" PRIu64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == unlim )
+        LogMessage(fmt, ind, caption, static_cast<unsigned long long>(val), " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, static_cast<unsigned long long>(val), "");
+}
+
+void ConfigLogger::log_limit(const char* caption, long long val, int unlim, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRId64 "%s\n" : CAPTION "%" PRId64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == unlim )
+        LogMessage(fmt, ind, caption, val, " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, val, "");
+}
+
+void ConfigLogger::log_limit(const char* caption, unsigned long long val, unsigned int unlim,
+    bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu64 "%s\n" : CAPTION "%" PRIu64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == unlim )
+        LogMessage(fmt, ind, caption, val, " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, val, "");
+}
+
 void ConfigLogger::log_limit(const char* caption, int val, int unlim, int disable, bool subopt)
 {
-    auto fmt = subopt ? SUB_CAPTION "%d%s\n" : CAPTION "%d%s\n";
+    auto fmt = subopt ? SUB_CAPTION "%" PRId32 "%s\n" : CAPTION "%" PRId32 "%s\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
 
     if ( val == disable )
@@ -355,23 +422,69 @@ void ConfigLogger::log_limit(const char* caption, int val, int unlim, int disabl
         LogMessage(fmt, ind, caption, val, "");
 }
 
-void ConfigLogger::log_limit(const char* caption, int val, int unlim, bool subopt)
+void ConfigLogger::log_limit(const char* caption, unsigned int val, unsigned int unlim,
+    unsigned int disable, bool subopt)
 {
-    auto fmt = subopt ? SUB_CAPTION "%d%s\n" : CAPTION "%d%s\n";
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu32 "%s\n" : CAPTION "%" PRIu32 "%s\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
 
-    if ( val == unlim )
+    if ( val == disable )
+        LogMessage(fmt, ind, caption, val, " (disabled)");
+    else if ( val == unlim )
         LogMessage(fmt, ind, caption, val, " (unlimited)");
     else
         LogMessage(fmt, ind, caption, val, "");
 }
 
-void ConfigLogger::log_limit(const char* caption, int64_t val, int64_t unlim, bool subopt)
+void ConfigLogger::log_limit(const char* caption, long val, int unlim, int disable, bool subopt)
 {
     auto fmt = subopt ? SUB_CAPTION "%" PRId64 "%s\n" : CAPTION "%" PRId64 "%s\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
 
-    if ( val == unlim )
+    if ( val == disable )
+        LogMessage(fmt, ind, caption, static_cast<long long>(val), " (disabled)");
+    else if ( val == unlim )
+        LogMessage(fmt, ind, caption, static_cast<long long>(val), " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, static_cast<long long>(val), "");
+}
+
+void ConfigLogger::log_limit(const char* caption, unsigned long val, unsigned int unlim,
+    unsigned int disable, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu64 "%s\n" : CAPTION "%" PRIu64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == disable )
+        LogMessage(fmt, ind, caption, static_cast<unsigned long long>(val), " (disabled)");
+    else if ( val == unlim )
+        LogMessage(fmt, ind, caption, static_cast<unsigned long long>(val), " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, static_cast<unsigned long long>(val), "");
+}
+
+void ConfigLogger::log_limit(const char* caption, long long val, int unlim, int disable, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRId64 "%s\n" : CAPTION "%" PRId64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == disable )
+        LogMessage(fmt, ind, caption, val, " (disabled)");
+    else if ( val == unlim )
+        LogMessage(fmt, ind, caption, val, " (unlimited)");
+    else
+        LogMessage(fmt, ind, caption, val, "");
+}
+
+void ConfigLogger::log_limit(const char* caption, unsigned long long val, unsigned int unlim,
+    unsigned int disable, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu64 "%s\n" : CAPTION "%" PRIu64 "%s\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    if ( val == disable )
+        LogMessage(fmt, ind, caption, val, " (disabled)");
+    else if ( val == unlim )
         LogMessage(fmt, ind, caption, val, " (unlimited)");
     else
         LogMessage(fmt, ind, caption, val, "");
@@ -385,7 +498,7 @@ void ConfigLogger::log_value(const char* caption, int n, const char* descr, bool
     LogMessage(fmt, ind, caption, n, descr);
 }
 
-void ConfigLogger::log_value(const char* caption, int32_t n, bool subopt)
+void ConfigLogger::log_value(const char* caption, int n, bool subopt)
 {
     auto fmt = subopt ? SUB_CAPTION "%" PRId32 "\n" : CAPTION "%" PRId32 "\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
@@ -393,7 +506,7 @@ void ConfigLogger::log_value(const char* caption, int32_t n, bool subopt)
     LogMessage(fmt, ind, caption, n);
 }
 
-void ConfigLogger::log_value(const char* caption, uint32_t n, bool subopt)
+void ConfigLogger::log_value(const char* caption, unsigned int n, bool subopt)
 {
     auto fmt = subopt ? SUB_CAPTION "%" PRIu32 "\n" : CAPTION "%" PRIu32 "\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
@@ -401,7 +514,23 @@ void ConfigLogger::log_value(const char* caption, uint32_t n, bool subopt)
     LogMessage(fmt, ind, caption, n);
 }
 
-void ConfigLogger::log_value(const char* caption, int64_t n, bool subopt)
+void ConfigLogger::log_value(const char* caption, long n, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRId64 "\n" : CAPTION "%" PRId64 "\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    LogMessage(fmt, ind, caption, static_cast<long long>(n));
+}
+
+void ConfigLogger::log_value(const char* caption, unsigned long n, bool subopt)
+{
+    auto fmt = subopt ? SUB_CAPTION "%" PRIu64 "\n" : CAPTION "%" PRIu64 "\n";
+    auto ind = subopt ? indention + strlen(caption) + 2 : indention;
+
+    LogMessage(fmt, ind, caption, static_cast<unsigned long long>(n));
+}
+
+void ConfigLogger::log_value(const char* caption, long long n, bool subopt)
 {
     auto fmt = subopt ? SUB_CAPTION "%" PRId64 "\n" : CAPTION "%" PRId64 "\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
@@ -409,7 +538,7 @@ void ConfigLogger::log_value(const char* caption, int64_t n, bool subopt)
     LogMessage(fmt, ind, caption, n);
 }
 
-void ConfigLogger::log_value(const char* caption, uint64_t n, bool subopt)
+void ConfigLogger::log_value(const char* caption, unsigned long long n, bool subopt)
 {
     auto fmt = subopt ? SUB_CAPTION "%" PRIu64 "\n" : CAPTION "%" PRIu64 "\n";
     auto ind = subopt ? indention + strlen(caption) + 2 : indention;
index 9356afa631b2ffcba2889d1e1ae2b913596f1da7..a26701243234339665c5af41e011e032441f909e 100644 (file)
@@ -69,18 +69,36 @@ class SO_PUBLIC ConfigLogger final
 {
 public:
     ConfigLogger() = delete;
+
     static void log_option(const char* caption);
+
     static bool log_flag(const char* caption, bool flag, bool subopt = false);
+
     static void log_limit(const char* caption, int val, int unlim, bool subopt = false);
+    static void log_limit(const char* caption, unsigned int val, unsigned int unlim, bool subopt = false);
+    static void log_limit(const char* caption, long val, int unlim, bool subopt = false);
+    static void log_limit(const char* caption, unsigned long val, unsigned int unlim, bool subopt = false);
+    static void log_limit(const char* caption, long long val, int unlim, bool subopt = false);
+    static void log_limit(const char* caption, unsigned long long val, unsigned int unlim, bool subopt = false);
+
     static void log_limit(const char* caption, int val, int unlim, int disable, bool subopt = false);
-    static void log_limit(const char* caption, int64_t val, int64_t unlim, bool subopt = false);
+    static void log_limit(const char* caption, unsigned int val, unsigned int unlim, unsigned int disable, bool subopt = false);
+    static void log_limit(const char* caption, long val, int unlim, int disable, bool subopt = false);
+    static void log_limit(const char* caption, unsigned long val, unsigned int unlim, unsigned int disable, bool subopt = false);
+    static void log_limit(const char* caption, long long val, int unlim, int disable, bool subopt = false);
+    static void log_limit(const char* caption, unsigned long long val, unsigned int unlim, unsigned int disable, bool subopt = false);
+
     static void log_value(const char* caption, int n, const char* descr, bool subopt = false);
-    static void log_value(const char* caption, int32_t n, bool subopt = false);
-    static void log_value(const char* caption, uint32_t n, bool subopt = false);
-    static void log_value(const char* caption, int64_t n, bool subopt = false);
-    static void log_value(const char* caption, uint64_t n, bool subopt = false);
+
+    static void log_value(const char* caption, int n, bool subopt = false);
+    static void log_value(const char* caption, unsigned int n, bool subopt = false);
+    static void log_value(const char* caption, long n, bool subopt = false);
+    static void log_value(const char* caption, unsigned long n, bool subopt = false);
+    static void log_value(const char* caption, long long n, bool subopt = false);
+    static void log_value(const char* caption, unsigned long long n, bool subopt = false);
     static void log_value(const char* caption, double n, bool subopt = false);
     static void log_value(const char* caption, const char* str, bool subopt = false);
+
     static void log_list(const char* caption, const char* list, const char* prefix = " ", bool subopt = false);
     static void log_list(const char* list);
 private:
index 13cd42f34f678dad0b426fff30454cce07b9829d..1a552ee8fc302f507953cee235bd93d169178965 100644 (file)
@@ -87,7 +87,7 @@ void AppIdConfig::show() const
 
     ConfigLogger::log_flag("log_all_sessions", log_all_sessions);
     ConfigLogger::log_flag("log_stats", log_stats);
-    ConfigLogger::log_value("memcap", static_cast<uint64_t>(memcap));
+    ConfigLogger::log_value("memcap", memcap);
 }
 
 void AppIdContext::pterm()
index ff2881f5167be4f7d26781b17e3eec382183544b..6e1f66385df89743dda485842158687ec9b5c95e 100644 (file)
@@ -163,7 +163,7 @@ void PerfMonitor::show(const SnortConfig*) const
         ConfigLogger::log_value("flow_ports", config->flow_max_port_to_track);
 
     if ( ConfigLogger::log_flag("flow_ip", config->perf_flags & PERF_FLOWIP) )
-        ConfigLogger::log_value("flow_ip_memcap", static_cast<uint64_t>(config->flowip_memcap));
+        ConfigLogger::log_value("flow_ip_memcap", config->flowip_memcap);
 
     ConfigLogger::log_value("packets", config->pkt_cnt);
     ConfigLogger::log_value("seconds", config->sample_interval);
index 6ef7eaf84ed36ab11c2124e6a6f4f5e7d3605cdf..93a3f91551b7339e8b523bbbdad9af8f79d80833 100644 (file)
@@ -384,7 +384,7 @@ static std::string to_string(const IPSET* list)
 
 static void portscan_config_show(const PortscanConfig* config)
 {
-    ConfigLogger::log_value("memcap", static_cast<uint64_t>(config->memcap));
+    ConfigLogger::log_value("memcap", config->memcap);
     ConfigLogger::log_value("protos", get_protos(config->detect_scans).c_str());
     ConfigLogger::log_value("scan_types", get_types(config->detect_scan_type).c_str());
 
index e19b277344dd69f2fe3e0b0a5884923e1d6914e9..60048cdb54d1ee2b1ed36631eedd39132f39ef6f 100755 (executable)
@@ -163,8 +163,8 @@ void HttpInspect::show(const SnortConfig*) const
     for (auto s : params->js_norm_param.ignored_props)
         js_norm_prop_ignore += s + " ";
 
-    ConfigLogger::log_limit("request_depth", params->request_depth, -1LL);
-    ConfigLogger::log_limit("response_depth", params->response_depth, -1LL);
+    ConfigLogger::log_limit("request_depth", params->request_depth, -1);
+    ConfigLogger::log_limit("response_depth", params->response_depth, -1);
     ConfigLogger::log_flag("unzip", params->unzip);
     ConfigLogger::log_flag("normalize_utf", params->normalize_utf);
     ConfigLogger::log_flag("decompress_pdf", params->decompress_pdf);
index 39a458c39f3319512aefce312c1b02f0c8e2b1b5..f20ee21244f199385f0db47b7f11e4fc7df01bf0 100644 (file)
@@ -829,8 +829,8 @@ static void show_device(const NetFlowRule& d, bool is_exclude)
 
 void NetFlowInspector::show(const SnortConfig*) const
 {
-    ConfigLogger::log_value("flow_memcap", (uint64_t)config->flow_memcap);
-    ConfigLogger::log_value("template_memcap", (uint64_t)config->template_memcap);
+    ConfigLogger::log_value("flow_memcap", config->flow_memcap);
+    ConfigLogger::log_value("template_memcap", config->template_memcap);
     ConfigLogger::log_value("dump_file", config->dump_file);
     ConfigLogger::log_value("update_timeout", config->update_timeout);
     bool log_header = true;