]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4682: control: data race in ControlConn touch method fix
authorVolodymyr Shpyrka -X (vshpyrka - SOFTSERVE INC at Cisco) <vshpyrka@cisco.com>
Tue, 1 Apr 2025 14:23:04 +0000 (14:23 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Tue, 1 Apr 2025 14:23:04 +0000 (14:23 +0000)
Merge in SNORT/snort3 from ~VSHPYRKA/snort3:ctrl_connn_dr_fix to master

Squashed commit of the following:

commit 6efb3d5acac88957a17886969ae9145fb21b0222
Author: Volodymyr Shpyrka <vshpyrka@cisco.com>
Date:   Mon Mar 31 03:24:58 2025 -0400

    control: fix data race in ControlConn touch method

src/control/control.cc
src/control/control.h
src/control/control_mgmt.cc

index 6f28754946ac1e47a4cf2cd56ee394a45fb2ea0f..679972464c05dea7c72fe35a83b1189bc6085b71 100644 (file)
@@ -196,12 +196,12 @@ void ControlConn::remove()
 
 void ControlConn::touch()
 {
-    touched = time(nullptr);
+    touched.store(time(nullptr), std::memory_order_relaxed);
 }
 
 time_t ControlConn::get_touched() const
 {
-    return touched;
+    return touched.load(std::memory_order_relaxed);
 }
 
 void ControlConn::unblock()
index b077aa9f560667583e5b9d7f9c2abd4aca866a1e..918086440c76f9db06958b8b811db48508e7af98 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef CONTROL_H
 #define CONTROL_H
 
+#include <atomic>
 #include <cstdarg>
 #include <ctime>
 #include <queue>
@@ -84,7 +85,7 @@ private:
     int blocked = 0; // a number of commands blocking the channel
     bool local = false;
     bool removed = false;
-    time_t touched;
+    std::atomic<time_t> touched;
 
     static std::vector<std::string> log_exclusion_list;
     static unsigned pending_cmds_count; //counter to serialize commands across control connections
index 236fe8786bef0577ff31158d8cd8d0cae9b8b124..c48e5fb444c57b99cb307076cdefa12b67a03663 100644 (file)
 using namespace snort;
 
 static constexpr unsigned MAX_CONTROL_FDS = 16;
+#ifndef REG_TEST
 static constexpr unsigned MAX_CONTROL_IDLE_TIME = 60;
+#else
+static constexpr unsigned MAX_CONTROL_IDLE_TIME = 5;
+#endif
 
 static int listener = -1;
 static socklen_t sock_addr_size = 0;