]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #757 in SNORT/snort3 from failed_init to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 19 Dec 2016 19:56:04 +0000 (14:56 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 19 Dec 2016 19:56:04 +0000 (14:56 -0500)
Squashed commit of the following:

commit 2f5ecada66689fc0abcb05bafc402c66ff6cbad2
Author: Michael Altizer <mialtize@cisco.com>
Date:   Mon Dec 19 13:29:31 2016 -0500

    Fix thread termination segfaults after DAQ module initialization fails

src/file_api/file_stats.cc
src/network_inspectors/appid/client_plugins/client_app_base.cc
src/network_inspectors/appid/detector_plugins/detector_http.cc
src/network_inspectors/appid/host_port_app_cache.cc
src/network_inspectors/appid/service_plugins/service_base.cc
src/network_inspectors/appid/service_state.cc
src/stream/ip/ip_defrag.cc

index 93a5049819f47988cc9e14da9435cfc3b26bb19f..747840061e1d9dbed2530ccd7f7d18a3bc4f24ce 100644 (file)
@@ -53,6 +53,9 @@ void file_stats_term()
 
 void file_stats_sum()
 {
+    if (!file_stats)
+        return;
+
     unsigned num = sizeof(file_totals) / sizeof(PegCount);
 
     for ( unsigned i = 0; i < num; ++i )
index 1966dfa03f1b7551de373d9ae76c45db2da9c6e7..c16b4a97d0e1777836ef2f756235ef16adff5256 100644 (file)
@@ -611,6 +611,9 @@ void clean_client_plugins()
     ClientPatternData* pd;
     RNAClientAppRecord* li;
 
+    if (!client_app_config)
+        return;
+
     if (client_app_config->tcp_patterns)
     {
         delete client_app_config->tcp_patterns;
@@ -653,6 +656,7 @@ void clean_client_plugins()
 
     clean_client_port_patterns();
     delete client_app_config;
+    client_app_config = nullptr;
 }
 
 /*
index ccb8f797599b2058b468bb1aec63a363fee34940..bb3e768d9e425686ad2a408958f19afc1c9bde5a 100644 (file)
@@ -967,6 +967,9 @@ int finalize_http_detector()
 
 void clean_http_detector()
 {
+    if (!detectorHttpConfig)
+        return;
+
     delete detectorHttpConfig->via_matcher;
     delete detectorHttpConfig->url_matcher;
     delete detectorHttpConfig->client_agent_matcher;
@@ -983,7 +986,9 @@ void clean_http_detector()
 
     CleanHttpPatternLists();
     delete httpPatternLists;
+
     delete detectorHttpConfig;
+    detectorHttpConfig = nullptr;
 }
 
 static inline void FreeMatchStructures(MatchedPatterns* mp)
index 07fc727665d94aefb62b05568bd2f8b89a8b713d..69671de9d1744438d5c23bfb3a332b8feae7e171 100644 (file)
@@ -38,24 +38,24 @@ struct HostPortKey
         padding = 0;
     }
 
-       bool operator<(HostPortKey right) const
-       {
-               if( ip.less_than(right.ip) )
-                       return true;
-               else if( right.ip.less_than(ip) )
-                       return false;
-               else
-               {
-                       if( port < right.port)
-                               return true;
-                       else if( right.port < port )
-                               return false;
-                       else if( proto < right.proto)
-                               return true;
-                       else
-                               return false;
-               }
-       }
+    bool operator<(HostPortKey right) const
+    {
+        if( ip.less_than(right.ip) )
+            return true;
+        else if( right.ip.less_than(ip) )
+            return false;
+        else
+        {
+            if( port < right.port)
+                return true;
+            else if( right.port < port )
+                return false;
+            else if( proto < right.proto)
+                return true;
+            else
+                return false;
+        }
+    }
 
     SfIp ip;
     uint16_t port;
@@ -68,14 +68,17 @@ THREAD_LOCAL std::map<HostPortKey, HostPortVal>* host_port_cache = nullptr;
 
 void HostPortCache::initialize()
 {
-       host_port_cache = new std::map<HostPortKey, HostPortVal>;
+    host_port_cache = new std::map<HostPortKey, HostPortVal>;
 }
 
 void HostPortCache::terminate()
 {
-       host_port_cache->empty();
-       delete host_port_cache;
-       host_port_cache = nullptr;
+    if (host_port_cache)
+    {
+        host_port_cache->empty();
+        delete host_port_cache;
+        host_port_cache = nullptr;
+    }
 }
 
 HostPortVal* HostPortCache::find(const SfIp* ip, uint16_t port, IpProtocol protocol)
@@ -89,9 +92,9 @@ HostPortVal* HostPortCache::find(const SfIp* ip, uint16_t port, IpProtocol proto
     std::map<HostPortKey, HostPortVal>::iterator it;
     it = host_port_cache->find(hk);
     if (it != host_port_cache->end())
-       return &it->second;
+        return &it->second;
     else
-       return nullptr;
+        return nullptr;
 }
 
 bool HostPortCache::add(const SfIp* ip, uint16_t port, IpProtocol proto, unsigned type, AppId appId)
index 13e043f6ad5c5525c82bed0dfd3176c81295c5d6..ea48c9c05176d7dd7bf38d072fe0a0ac9f25ccaf 100644 (file)
@@ -788,6 +788,9 @@ void clean_service_plugins()
     FpSMBData* sd;
     DHCPInfo* info;
 
+    if (!service_config)
+        return;
+
     if (service_config->tcp_patterns)
     {
         delete service_config->tcp_patterns;
@@ -859,6 +862,7 @@ void clean_service_plugins()
     clean_service_port_patterns();
 
     delete service_config;
+    service_config = nullptr;
 }
 
 static int AppIdPatternPrecedence(const void* a, const void* b)
index 96feeea87b5deccb3089876faf5c14e07ae4f19c..b4b136be6ab6f299267416641595c396f8723ca1 100644 (file)
@@ -84,6 +84,9 @@ void AppIdServiceState::initialize(unsigned long)
 
 void AppIdServiceState::clean(void)
 {
+    if (!service_state_cache)
+        return;
+
        for( auto& kv : *service_state_cache )
        delete kv.second;
 
index da4c4b0c199e742eeec4bd3c9755f144361a2a5e..29f89df45d36b19834c6b9f4146bfd10e73b005e 100644 (file)
@@ -1072,6 +1072,9 @@ void Defrag::tinit()
 
 void Defrag::tterm()
 {
+    if (!defrag_pkts)
+        return;
+
     for (int i = 0; i < layers; i++)
     {
         if (defrag_pkts[i] != nullptr)