From c9bea1f8640459afd72f9ca19e9719cdcee182aa Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 7 Jan 2026 14:23:03 +0800 Subject: [PATCH 1/2] Improve the robustness of the TopicEndpointInfo constructor Signed-off-by: Barry Xu --- .../include/rclcpp/node_interfaces/node_graph_interface.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp b/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp index 117f298707..44df9fd2dc 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp @@ -57,9 +57,9 @@ class TopicEndpointInfo /// Construct a TopicEndpointInfo from a rcl_topic_endpoint_info_t. RCLCPP_PUBLIC explicit TopicEndpointInfo(const rcl_topic_endpoint_info_t & info) - : node_name_(info.node_name), - node_namespace_(info.node_namespace), - topic_type_(info.topic_type), + : node_name_(info.node_name ? info.node_name : ""), + node_namespace_(info.node_namespace ? info.node_namespace : ""), + topic_type_(info.topic_type ? info.topic_type : ""), endpoint_type_(static_cast(info.endpoint_type)), qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile), topic_type_hash_(info.topic_type_hash) From fafb5cc9cd70ff73800276e58375f7890fbeb80b Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Fri, 9 Jan 2026 10:21:26 +0800 Subject: [PATCH 2/2] Improve TopicEndpointInfo constructor to validate input parameters Signed-off-by: Barry Xu --- .../rclcpp/node_interfaces/node_graph_interface.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp b/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp index 44df9fd2dc..a548579585 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp @@ -57,13 +57,17 @@ class TopicEndpointInfo /// Construct a TopicEndpointInfo from a rcl_topic_endpoint_info_t. RCLCPP_PUBLIC explicit TopicEndpointInfo(const rcl_topic_endpoint_info_t & info) - : node_name_(info.node_name ? info.node_name : ""), - node_namespace_(info.node_namespace ? info.node_namespace : ""), - topic_type_(info.topic_type ? info.topic_type : ""), - endpoint_type_(static_cast(info.endpoint_type)), + : endpoint_type_(static_cast(info.endpoint_type)), qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile), topic_type_hash_(info.topic_type_hash) { + if (!info.node_name || !info.node_namespace || !info.topic_type) { + throw std::invalid_argument("Constructor TopicEndpointInfo with invalid topic endpoint info"); + } + node_name_ = info.node_name; + node_namespace_ = info.node_namespace; + topic_type_ = info.topic_type; + std::copy(info.endpoint_gid, info.endpoint_gid + RMW_GID_STORAGE_SIZE, endpoint_gid_.begin()); }