]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3442: appid: Added lock_guard to prevent data race on reload
authorMasud Hasan (mashasan) <mashasan@cisco.com>
Tue, 31 May 2022 16:26:13 +0000 (16:26 +0000)
committerMasud Hasan (mashasan) <mashasan@cisco.com>
Tue, 31 May 2022 16:26:13 +0000 (16:26 +0000)
Merge in SNORT/snort3 from ~OSTEPANO/snort3:tasan_appid_reload to master

Squashed commit of the following:

commit 5af9c9ad1b0ed389fb35d0d3cfff45dae3df46a8
Author: ostepano <ostepano@cisco.com>
Date:   Tue May 24 09:15:25 2022 -0400

    appid: Added lock_guard to prevent data race on reload

src/network_inspectors/appid/appid_peg_counts.cc

index 8f52b4ada1e0528536bfb958079267549edc7a5e..9413a871d09bbbf200cf1aa94c37121deab3ade0 100644 (file)
@@ -92,18 +92,24 @@ void AppIdPegCounts::sum_stats()
     if (!appid_peg_counts)
         return;
 
-    const unsigned peg_num = appid_peg_counts->size() ? (appid_peg_counts->size() - 1) : 0;
-    const AppIdDynamicPeg* ptr = (AppIdDynamicPeg*)appid_peg_counts->data();
+    static std::mutex r_mutex;
 
-    for ( unsigned i = 0; i < peg_num; ++i )
     {
+        std::lock_guard<std::mutex> _lock(r_mutex);
+        const unsigned peg_num = appid_peg_counts->size() ? (appid_peg_counts->size() - 1) : 0;
+        const AppIdDynamicPeg* ptr = (AppIdDynamicPeg*)appid_peg_counts->data();
+
+        for ( unsigned i = 0; i < peg_num; ++i )
+        {
+            for (unsigned j = 0; j < DetectorPegs::NUM_APPID_DETECTOR_PEGS; ++j)
+                appid_dynamic_sum[i].stats[j] += ptr[i].stats[j];
+        }
+
+        // unknown_app stats
         for (unsigned j = 0; j < DetectorPegs::NUM_APPID_DETECTOR_PEGS; ++j)
-            appid_dynamic_sum[i].stats[j] += ptr[i].stats[j];
+            appid_dynamic_sum[SF_APPID_MAX].stats[j] += ptr[peg_num].stats[j];
     }
-
-    // unknown_app stats
-    for (unsigned j = 0; j < DetectorPegs::NUM_APPID_DETECTOR_PEGS; ++j)
-        appid_dynamic_sum[SF_APPID_MAX].stats[j] += ptr[peg_num].stats[j];
+    
 }
 
 void AppIdPegCounts::inc_service_count(AppId id)