From 2f2e0f45da0aec53f92ac4034e5e3c52545813bd Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Sat, 10 Jan 2026 22:35:59 +0800 Subject: [PATCH] Improve the robustness of the TopicEndpointInfo constructor (#3013) * Improve the robustness of the TopicEndpointInfo constructor Signed-off-by: Barry Xu * Improve TopicEndpointInfo constructor to validate input parameters Signed-off-by: Barry Xu --------- Signed-off-by: Barry Xu (cherry picked from commit 7f783cbf587a2897572263b48b9583d8021f3958) --- .../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 80abc308c1..a5168db3d4 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp @@ -53,13 +53,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), - node_namespace_(info.node_namespace), - 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()); }