]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4756: file_api: introduced atomicity for is_file_service_enabled
authorAshutosh Gupta (ashugup3) <ashugup3@cisco.com>
Thu, 22 May 2025 08:14:38 +0000 (08:14 +0000)
committerLokesh Bevinamarad (lbevinam) <lbevinam@cisco.com>
Thu, 22 May 2025 08:14:38 +0000 (08:14 +0000)
Merge in SNORT/snort3 from ~ASHUGUP3/snort3:bug_CSCwn79296 to master

Squashed commit of the following:

commit e3162b2fbcb9f865c9a423e0aa4a1ff22892b12e
Author: ashutosh <ashugup3@cisco.com>
Date:   Thu May 22 10:42:28 2025 +0530

    file_api: introduced atomicity for is_file_service_enabled

src/file_api/file_service.cc
src/file_api/file_service.h

index 99ca9d8d8bc39a3336392739882554be2172a407..8860575b837b6aa48c97dededb896ade9884459f 100644 (file)
@@ -41,7 +41,7 @@
 
 using namespace snort;
 
-bool FileService::file_type_id_enabled = false;
+std::atomic<bool> FileService::file_type_id_enabled(false);
 bool FileService::file_signature_enabled = false;
 bool FileService::file_capture_enabled = false;
 bool FileService::file_processing_initiated = false;
@@ -127,7 +127,7 @@ void FileService::thread_term()
 
 void FileService::enable_file_type()
 {
-    file_type_id_enabled = true;
+    file_type_id_enabled.store(true, std::memory_order_relaxed);
 }
 
 void FileService::enable_file_signature()
@@ -144,7 +144,7 @@ void FileService::enable_file_capture()
 
 bool FileService::is_file_service_enabled()
 {
-    return (file_type_id_enabled or file_signature_enabled);
+    return (file_type_id_enabled.load() or file_signature_enabled);
 }
 
 /* Get maximal file depth based on configuration
@@ -170,7 +170,7 @@ void FileService::set_max_file_depth(const SnortConfig* sc)
     if (!file_config)
         return;
 
-    if (file_type_id_enabled)
+    if (file_type_id_enabled.load())
     {
         file_config->file_depth = file_config->file_type_depth;
     }
index 52ce4cae02e72b28c582f4541a82d433cc5a6b00..aa99307bc5721bd72670c4b11356a16f4d7e75e1 100644 (file)
@@ -55,7 +55,7 @@ public:
     static void enable_file_type();
     static void enable_file_signature();
     static void enable_file_capture();
-    static bool is_file_type_id_enabled() { return file_type_id_enabled; }
+    static bool is_file_type_id_enabled() { return file_type_id_enabled.load(); }
     static bool is_file_signature_enabled() { return file_signature_enabled; }
     static bool is_file_capture_enabled() { return file_capture_enabled; }
     static bool is_file_service_enabled();
@@ -66,7 +66,7 @@ public:
     static DecodeConfig decode_conf;
 
 private:
-    static bool file_type_id_enabled;
+    static std::atomic<bool> file_type_id_enabled;
     static bool file_signature_enabled;
     static bool file_capture_enabled;
     static bool file_processing_initiated;