]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4947: mp_data_bus: fixing coverity issues
authorUmang Sharma (umasharm) <umasharm@cisco.com>
Tue, 21 Oct 2025 18:08:49 +0000 (18:08 +0000)
committerChris Sherwin (chsherwi) <chsherwi@cisco.com>
Tue, 21 Oct 2025 18:08:49 +0000 (18:08 +0000)
Merge in SNORT/snort3 from ~UMASHARM/snort3:mpdbus_coverity to master

Squashed commit of the following:

commit 0d1fa67aa85e084c72dbe5f161e551c0455ed14f
Author: Umang Sharma <umasharm@cisco.com>
Date:   Thu Oct 16 11:55:05 2025 -0400

    mp_data_bus: fixing coverity issues

src/connectors/unixdomain_connector/unixdomain_connector.cc
src/framework/mp_data_bus.cc
src/mp_transport/mp_unix_transport/mp_unix_transport.cc

index 43d35b3878ec565088346efa1cded67f827262bb..690034fccde0f34b55e4ab641482f2a2d4d6a579 100644 (file)
@@ -597,7 +597,7 @@ void UnixDomainConnectorListener::start_accepting_connections(UnixDomainConnecto
     assert(sock_path);
 
     should_accept = true;
-    accept_thread = new std::thread([this, handler, config]()
+    accept_thread = new std::thread([this, handler = std::move(handler), config]()
     {
         sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
         if (sock_fd == -1) {
index 68338701e336c9ab947377a6e3bf27a8ca9ef307..dcae9b53aa90bb32959bfe16b192b90590a05503 100644 (file)
@@ -268,6 +268,7 @@ void MPDataBus::process_event_queue()
 
     std::unique_lock<std::mutex> u_lock(queue_mutex);
 
+    // coverity[wait_not_in_locked_loop:FALSE]
     if( (std::cv_status::timeout == queue_cv.wait_for(u_lock, std::chrono::milliseconds(WORKER_THREAD_SLEEP))) and
         mp_event_queue->empty() )
         return;
@@ -328,7 +329,7 @@ void MPDataBus::stop_worker_thread()
     worker_thread.reset();
 }
 
-static bool compare(DataHandler* a, DataHandler* b)
+static bool compare(const DataHandler* a, const DataHandler* b)
 {
     if ( a->order and b->order )
         return a->order < b->order;
@@ -424,13 +425,13 @@ void MPDataBus::dump_stats(ControlConn *ctrlconn, const char *module_name)
         auto mod_stats = mp_pub_stats[mod_id->second];
 
         LogMessage("MPDataBus Stats for %s\n", module_name);
-        show_stats((PegCount*)&mod_stats, mp_databus_pegs, array_size(mp_databus_pegs)-1);
+        show_stats(reinterpret_cast<PegCount*>(&mod_stats), mp_databus_pegs, array_size(mp_databus_pegs)-1);
     }
     else
     {
         sum_stats();
         
-        show_stats((PegCount*)&mp_global_stats, mp_databus_pegs, array_size(mp_databus_pegs)-1);
+        show_stats(reinterpret_cast<PegCount*>(&mp_global_stats), mp_databus_pegs, array_size(mp_databus_pegs)-1);
 
         auto transport_module = ModuleManager::get_module(transport.c_str());
         if(transport_module)
@@ -525,6 +526,7 @@ void snort::MPDataBus::show_channel_status(ControlConn *ctrlconn)
     for (unsigned int i = 0; i < size; i++)
     {
         const auto& channel = transport_status[i];
+        // coverity[missing_lock:SUPPRESS]
         response += "Channel ID: " + std::to_string(channel.id) + ", Name: " + channel.name + ", Status: " + channel.get_status_string() + "\n";
     }
 
index 1c2ff2c91dd84f73851fc191fe1d8474ae87b058..92f17e52834093b7f96845f289d75815a45d5966 100644 (file)
@@ -190,6 +190,7 @@ void MPUnixDomainTransport::register_event_helpers(const unsigned& pub_id, const
     
     this->event_helpers[pub_id] = SerializeFunctionHandle();
     this->event_helpers[pub_id].serialize_functions.insert({event_id, std::move(helper)});
+    // coverity[return_with_moved_parameter:SUPPRESS]
 }
 
 void MPUnixDomainTransport::register_receive_handler(const TransportReceiveEventHandler& handler)
@@ -382,12 +383,20 @@ void MPUnixDomainTransport::init_side_channels()
 
     this->is_running = true;
 
-    struct stat st;
-    if (::stat(config->unix_domain_socket_path.c_str(), &st) != 0 || !S_ISDIR(st.st_mode))
+    if (mkdir(config->unix_domain_socket_path.c_str(), 0755) != 0)
     {
-        if (mkdir(config->unix_domain_socket_path.c_str(), 0755) != 0)
+        if (errno == EEXIST)
         {
-            MPTransportLog("Failed to create directory %s\n", config->unix_domain_socket_path.c_str());
+            struct stat st;
+            if (::stat(config->unix_domain_socket_path.c_str(), &st) == 0 && !S_ISDIR(st.st_mode))
+            {
+                MPTransportLog("Path %s exists but is not a directory: %s\n", config->unix_domain_socket_path.c_str(), strerror(errno));
+                return;
+            }
+        }
+        else
+        {
+            MPTransportLog("Failed to create directory %s: %s\n", config->unix_domain_socket_path.c_str(), strerror(errno));
             return;
         }
     }
@@ -415,7 +424,7 @@ void MPUnixDomainTransport::init_side_channels()
             unix_config->max_retries = 0;
             unix_config->connect_timeout_seconds = 0;
         }
-        unix_config->paths.push_back(listen_path);
+        unix_config->paths.push_back(std::move(listen_path));
 
         unix_listener->start_accepting_connections( std::bind(&MPUnixDomainTransport::handle_new_connection, this, std::placeholders::_1, std::placeholders::_2, instance_id+1), unix_config);