From: Russ Combs (rucombs) Date: Mon, 19 Dec 2016 19:56:04 +0000 (-0500) Subject: Merge pull request #757 in SNORT/snort3 from failed_init to master X-Git-Tag: 3.0.0-233~133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91a4661a9c277e67c0cf4e571dda30c4d555dfde;p=thirdparty%2Fsnort3.git Merge pull request #757 in SNORT/snort3 from failed_init to master Squashed commit of the following: commit 2f5ecada66689fc0abcb05bafc402c66ff6cbad2 Author: Michael Altizer Date: Mon Dec 19 13:29:31 2016 -0500 Fix thread termination segfaults after DAQ module initialization fails --- diff --git a/src/file_api/file_stats.cc b/src/file_api/file_stats.cc index 93a504981..747840061 100644 --- a/src/file_api/file_stats.cc +++ b/src/file_api/file_stats.cc @@ -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 ) diff --git a/src/network_inspectors/appid/client_plugins/client_app_base.cc b/src/network_inspectors/appid/client_plugins/client_app_base.cc index 1966dfa03..c16b4a97d 100644 --- a/src/network_inspectors/appid/client_plugins/client_app_base.cc +++ b/src/network_inspectors/appid/client_plugins/client_app_base.cc @@ -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; } /* diff --git a/src/network_inspectors/appid/detector_plugins/detector_http.cc b/src/network_inspectors/appid/detector_plugins/detector_http.cc index ccb8f7975..bb3e768d9 100644 --- a/src/network_inspectors/appid/detector_plugins/detector_http.cc +++ b/src/network_inspectors/appid/detector_plugins/detector_http.cc @@ -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) diff --git a/src/network_inspectors/appid/host_port_app_cache.cc b/src/network_inspectors/appid/host_port_app_cache.cc index 07fc72766..69671de9d 100644 --- a/src/network_inspectors/appid/host_port_app_cache.cc +++ b/src/network_inspectors/appid/host_port_app_cache.cc @@ -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* host_port_cache = nullptr; void HostPortCache::initialize() { - host_port_cache = new std::map; + host_port_cache = new std::map; } 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::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) diff --git a/src/network_inspectors/appid/service_plugins/service_base.cc b/src/network_inspectors/appid/service_plugins/service_base.cc index 13e043f6a..ea48c9c05 100644 --- a/src/network_inspectors/appid/service_plugins/service_base.cc +++ b/src/network_inspectors/appid/service_plugins/service_base.cc @@ -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) diff --git a/src/network_inspectors/appid/service_state.cc b/src/network_inspectors/appid/service_state.cc index 96feeea87..b4b136be6 100644 --- a/src/network_inspectors/appid/service_state.cc +++ b/src/network_inspectors/appid/service_state.cc @@ -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; diff --git a/src/stream/ip/ip_defrag.cc b/src/stream/ip/ip_defrag.cc index da4c4b0c1..29f89df45 100644 --- a/src/stream/ip/ip_defrag.cc +++ b/src/stream/ip/ip_defrag.cc @@ -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)