]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2521 in SNORT/snort3 from ~SELYSENK/snort3:trace_segfault to...
authorBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Tue, 20 Oct 2020 17:52:37 +0000 (17:52 +0000)
committerBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Tue, 20 Oct 2020 17:52:37 +0000 (17:52 +0000)
Squashed commit of the following:

commit dcb8788f355a62d51885ee1d399a7cab90f4ed45
Author: Serhii Lysenko <selysenk@cisco.com>
Date:   Mon Oct 5 17:26:20 2020 +0300

    trace: skip trace reload if no initial config present

src/main.cc
src/main/snort.cc
src/trace/trace_config.cc
src/trace/trace_config.h
src/trace/trace_module.cc
src/trace/trace_swap.cc

index a4bd42328add93cadb435ec31fc1d7c118e6c5fd..ae7f2ea7920b3fe99b9b2d89cad368214ee47b14 100644 (file)
@@ -52,6 +52,8 @@
 #include "target_based/host_attributes.h"
 #include "time/periodic.h"
 #include "trace/trace_api.h"
+#include "trace/trace_config.h"
+#include "trace/trace_logger.h"
 #include "utils/util.h"
 #include "utils/safec.h"
 
@@ -382,6 +384,13 @@ int main_reload_config(lua_State* L)
     else
         LogMessage("No host attribute table loaded\n");
 
+    if ( !old or !old->trace_config or !old->trace_config->initialized )
+    {
+        LogMessage("== WARNING: Trace module was not configured during "
+            "initial startup. Ignoring the new trace configuration.\n");
+        sc->trace_config->clear();
+    }
+
     PluginManager::reload_so_plugins_cleanup(sc);
     SnortConfig::set_conf(sc);
     TraceApi::thread_reinit(sc->trace_config);
index 4c41f416941d53c4814c7c9bc9989ef654dfa7e7..9d435a5272a3066027590a6729854b0cd20793e2 100644 (file)
@@ -68,6 +68,8 @@
 #include "target_based/host_attributes.h"
 #include "time/periodic.h"
 #include "trace/trace_api.h"
+#include "trace/trace_config.h"
+#include "trace/trace_logger.h"
 #include "utils/util.h"
 
 #ifdef PIGLET
@@ -535,9 +537,19 @@ SnortConfig* Snort::get_updated_policy(
 
     if ( fname )
     {
+        bool uninitialized_trace = !other_conf->trace_config or
+            !other_conf->trace_config->initialized;
+
         Shell sh = Shell(fname);
         sh.configure(sc, false, true);
 
+        if ( uninitialized_trace )
+        {
+            LogMessage("== WARNING: Trace module was not configured during "
+                "initial startup. Ignoring the new trace configuration.\n");
+            sc->trace_config->clear();
+        }
+
         if ( ModuleManager::get_errors() || !sc->verify() )
         {
             sc->cloned = true;
index a427f68a28381e5683e32ded6573d473087a47b4..04078f2fee81fa82c577771c7f16673abaf159e2 100644 (file)
@@ -72,6 +72,14 @@ bool TraceConfig::set_trace(const std::string& module_name, const std::string& t
     return false;
 }
 
+void TraceConfig::clear()
+{
+    clear_traces();
+    initialized = false;
+    delete logger_factory;
+    logger_factory = nullptr;
+}
+
 void TraceConfig::clear_traces()
 {
     for ( auto& trace : traces )
index 320a06e010cd4c55d6cecb1730bcf76217bbf81e..c20cf61d303cad7d234fd79ba15a731b1a6e3b05 100644 (file)
@@ -39,13 +39,14 @@ public:
     bool set_trace(const std::string& module_name,
         const std::string& trace_option_name, uint8_t trace_level);
 
+    void clear();
     void clear_traces();
 
 public:
     snort::TraceLoggerFactory* logger_factory = nullptr;
     snort::PacketConstraints* constraints = nullptr;
     bool log_ntuple = false;
-
+    bool initialized = false;
 private:
     Traces traces;
 };
index b81277a1bb5d4a5c32ceb8e308e00b9ba1125a1d..b0c4b5a00a2e8df415776604f11084af8adc1505 100644 (file)
@@ -239,6 +239,8 @@ bool TraceModule::end(const char* fqn, int, SnortConfig* sc)
             trace_parser->finalize_constraints();
         }
 
+        trace_parser->get_trace_config().initialized = true;
+
         delete trace_parser;
         trace_parser = nullptr;
     }
index 094c2548c2185d81d8921269d156b207ee868ba8..d9a9715b6beacaf368b45f887367afe47ae2ede2 100644 (file)
@@ -145,9 +145,17 @@ void TraceSwap::print_msg() const
 
 static int set(lua_State* L)
 {
+    const SnortConfig* sc = SnortConfig::get_conf();
+
+    if ( !sc->trace_config->initialized )
+    {
+        LogMessage("== WARNING: Trace module was not configured during "
+            "initial startup. Ignoring the new trace configuration.\n");
+        return 0;
+    }
+
     // Create an overlay TraceConfig based on the current configuration
     // It will be set in a SnortConfig during TraceSwap execution and owned by it after
-    const SnortConfig* sc = SnortConfig::get_conf();
     TraceConfig* trace_config = new TraceConfig(sc->overlay_trace_config
         ? *sc->overlay_trace_config : *sc->trace_config);