From: Umang Sharma (umasharm) Date: Tue, 21 Oct 2025 18:08:49 +0000 (+0000) Subject: Pull request #4947: mp_data_bus: fixing coverity issues X-Git-Tag: 3.9.7.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04255b327a4fac528536b9e00c06ed247c4636e9;p=thirdparty%2Fsnort3.git Pull request #4947: mp_data_bus: fixing coverity issues Merge in SNORT/snort3 from ~UMASHARM/snort3:mpdbus_coverity to master Squashed commit of the following: commit 0d1fa67aa85e084c72dbe5f161e551c0455ed14f Author: Umang Sharma Date: Thu Oct 16 11:55:05 2025 -0400 mp_data_bus: fixing coverity issues --- diff --git a/src/connectors/unixdomain_connector/unixdomain_connector.cc b/src/connectors/unixdomain_connector/unixdomain_connector.cc index 43d35b387..690034fcc 100644 --- a/src/connectors/unixdomain_connector/unixdomain_connector.cc +++ b/src/connectors/unixdomain_connector/unixdomain_connector.cc @@ -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) { diff --git a/src/framework/mp_data_bus.cc b/src/framework/mp_data_bus.cc index 68338701e..dcae9b53a 100644 --- a/src/framework/mp_data_bus.cc +++ b/src/framework/mp_data_bus.cc @@ -268,6 +268,7 @@ void MPDataBus::process_event_queue() std::unique_lock 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(&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(&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"; } diff --git a/src/mp_transport/mp_unix_transport/mp_unix_transport.cc b/src/mp_transport/mp_unix_transport/mp_unix_transport.cc index 1c2ff2c91..92f17e528 100644 --- a/src/mp_transport/mp_unix_transport/mp_unix_transport.cc +++ b/src/mp_transport/mp_unix_transport/mp_unix_transport.cc @@ -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);