From 79f136fa3f853b5c702dc7213da4942a0bac7ed3 Mon Sep 17 00:00:00 2001 From: Juan Lopez Fernandez Date: Fri, 2 Feb 2024 09:51:46 +0100 Subject: [PATCH] Add safety check Signed-off-by: Juan Lopez Fernandez --- src/cpp/fastdds/publisher/PublisherImpl.cpp | 33 ++++++++++--------- src/cpp/fastdds/subscriber/SubscriberImpl.cpp | 33 ++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/cpp/fastdds/publisher/PublisherImpl.cpp b/src/cpp/fastdds/publisher/PublisherImpl.cpp index af141c90e81..8a46c23fe08 100644 --- a/src/cpp/fastdds/publisher/PublisherImpl.cpp +++ b/src/cpp/fastdds/publisher/PublisherImpl.cpp @@ -245,22 +245,25 @@ DataWriter* PublisherImpl::create_datawriter( } // Check netmask filtering preconditions - fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( - rtps_participant()->getGuid()); - if (nullptr != rtps_impl) - { - std::vector netmask_filter_info = - rtps_impl->network_factory().netmask_filter_info(); - std::string error_msg; - if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().ignore_non_matching_locators, - error_msg) || - !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().external_unicast_locators, error_msg)) + if (nullptr != rtps_participant()) + { + fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( + rtps_participant()->getGuid()); + if (nullptr != rtps_impl) { - EPROSIMA_LOG_ERROR(PUBLISHER, - "Failed to create publisher -> " << error_msg); - return nullptr; + std::vector netmask_filter_info = + rtps_impl->network_factory().netmask_filter_info(); + std::string error_msg; + if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().ignore_non_matching_locators, + error_msg) || + !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().external_unicast_locators, error_msg)) + { + EPROSIMA_LOG_ERROR(PUBLISHER, + "Failed to create publisher -> " << error_msg); + return nullptr; + } } } diff --git a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp index e1d223b83b5..ed4d2b1dfb4 100644 --- a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp +++ b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp @@ -214,22 +214,25 @@ DataReader* SubscriberImpl::create_datareader( } // Check netmask filtering preconditions - fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( - rtps_participant()->getGuid()); - if (nullptr != rtps_impl) - { - std::vector netmask_filter_info = - rtps_impl->network_factory().netmask_filter_info(); - std::string error_msg; - if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().ignore_non_matching_locators, - error_msg) || - !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().external_unicast_locators, error_msg)) + if (nullptr != rtps_participant()) + { + fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( + rtps_participant()->getGuid()); + if (nullptr != rtps_impl) { - EPROSIMA_LOG_ERROR(SUBSCRIBER, - "Failed to create subscriber -> " << error_msg); - return nullptr; + std::vector netmask_filter_info = + rtps_impl->network_factory().netmask_filter_info(); + std::string error_msg; + if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().ignore_non_matching_locators, + error_msg) || + !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().external_unicast_locators, error_msg)) + { + EPROSIMA_LOG_ERROR(SUBSCRIBER, + "Failed to create subscriber -> " << error_msg); + return nullptr; + } } }