From: Steve Chew (stechew) Date: Fri, 9 May 2025 00:05:53 +0000 (+0000) Subject: Pull request #4732: Fix alias name X-Git-Tag: 3.8.1.0~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=995469a7d0be19e1c3673d5aab01bde7025ec5b0;p=thirdparty%2Fsnort3.git Pull request #4732: Fix alias name Merge in SNORT/snort3 from ~STECHEW/snort3:oleksii_alias_fix to master Squashed commit of the following: commit e14bdcd2196c9151048a2afb8559a64ab6fb4358 Author: Oleksii Shumeiko Date: Wed Apr 2 15:54:45 2025 +0300 framework: make alias name internal to inspector instance commit 32450f01541938b7e3b80d1b52df3ad172bf56c3 Author: Oleksii Shumeiko Date: Wed Apr 2 14:07:16 2025 +0300 managers: update formatting --- diff --git a/src/framework/inspector.cc b/src/framework/inspector.cc index b30d86a87..4747f240d 100644 --- a/src/framework/inspector.cc +++ b/src/framework/inspector.cc @@ -26,6 +26,7 @@ #include "main/thread_config.h" #include "protocols/packet.h" #include "stream/stream_splitter.h" +#include "utils/util.h" namespace snort { @@ -60,6 +61,7 @@ Inspector::~Inspector() assert(0 == ref_count[i]); delete[] ref_count; + delete[] alias_name; } bool Inspector::is_inactive() @@ -148,6 +150,12 @@ void Inspector::set_thread_specific_data(void* tsd) void* Inspector::get_thread_specific_data() const { return thread_specific_data->data[get_instance_id()]; } +void Inspector::set_alias_name(const char* name) +{ + delete[] alias_name; + alias_name = snort_strdup(name); +} + static const char* InspectorTypeNames[IT_MAX] = { "passive", diff --git a/src/framework/inspector.h b/src/framework/inspector.h index 20a3d1993..090c02fa6 100644 --- a/src/framework/inspector.h +++ b/src/framework/inspector.h @@ -43,7 +43,7 @@ struct SnortConfig; struct Packet; // this is the current version of the api -#define INSAPI_VERSION ((BASE_API_VERSION << 16) | 2) +#define INSAPI_VERSION ((BASE_API_VERSION << 16) | 3) struct InspectionBuffer { @@ -160,9 +160,7 @@ public: const char* get_name() const; - void set_alias_name(const char* name) - { alias_name = name; } - + void set_alias_name(const char*); const char* get_alias_name() const { return alias_name; } @@ -210,7 +208,6 @@ private: std::shared_ptr thread_specific_data; std::atomic_uint* ref_count; SnortProtocolId snort_protocol_id = 0; - // FIXIT-E Use std::string to avoid storing a pointer to external std::string buffers const char* alias_name = nullptr; uint64_t network_policy_user_id = 0; bool network_policy_user_id_set = false; diff --git a/src/managers/inspector_manager.cc b/src/managers/inspector_manager.cc index 2e36f3a83..e52698b3e 100644 --- a/src/managers/inspector_manager.cc +++ b/src/managers/inspector_manager.cc @@ -112,6 +112,7 @@ enum ReloadType typedef vector PHObjectList; typedef vector PHTSObjectLists; + struct ThreadSpecificHandlers { explicit ThreadSpecificHandlers(unsigned max) @@ -145,9 +146,9 @@ struct PHInstance bool is_reloaded() { - return ((reload_type == RELOAD_TYPE_REENABLED)or - (reload_type == RELOAD_TYPE_DELETED) or - (reload_type == RELOAD_TYPE_NEW)); + return reload_type == RELOAD_TYPE_REENABLED + or reload_type == RELOAD_TYPE_DELETED + or reload_type == RELOAD_TYPE_NEW; } ReloadType get_reload_type() @@ -181,14 +182,17 @@ PHInstance::~PHInstance() typedef vector PHGlobalList; typedef vector PHClassList; typedef vector PHInstanceList; + struct PHRemovedInstance { PHRemovedInstance(PHInstance* i, PHTSObjectLists& handlers) : instance(i), handlers(handlers) { } + PHInstance* instance; PHTSObjectLists& handlers; }; + typedef vector PHRemovedInstanceList; typedef list PHList; @@ -196,7 +200,6 @@ static PHGlobalList s_handlers; static PHList s_trash; static PHList s_trash2; static bool s_sorted = false; - static PHTSObjectLists s_tl_handlers; void InspectorManager::global_init() diff --git a/src/managers/test/get_inspector_test.cc b/src/managers/test/get_inspector_test.cc index 884234429..5ce0e8aaf 100644 --- a/src/managers/test/get_inspector_test.cc +++ b/src/managers/test/get_inspector_test.cc @@ -90,6 +90,9 @@ const SnortConfig* SnortConfig::get_conf() Module::Module(const char* name, const char*) : name(name), help(nullptr), params(nullptr), list(false) { } +void Inspector::set_alias_name(const char* n) +{ alias_name = n; } + class TestInspector : public Inspector { public: