From fabd65b9d3925445441e903c932d4f7d554b4d2b Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Mon, 22 Nov 2021 13:42:44 -0800 Subject: [PATCH] Length of size limited string is not checked https://github.com/ros2/rclcpp/issues/1827 Signed-off-by: Tomoya Fujita --- prover_interfaces/CMakeLists.txt | 4 +++ prover_interfaces/msg/StringLengthTest.msg | 1 + prover_rclcpp/CMakeLists.txt | 3 ++ prover_rclcpp/package.xml | 4 ++- prover_rclcpp/src/rclcpp_1827.cpp | 38 ++++++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 prover_interfaces/msg/StringLengthTest.msg create mode 100644 prover_rclcpp/src/rclcpp_1827.cpp diff --git a/prover_interfaces/CMakeLists.txt b/prover_interfaces/CMakeLists.txt index 5545305..ff04ef5 100644 --- a/prover_interfaces/CMakeLists.txt +++ b/prover_interfaces/CMakeLists.txt @@ -12,10 +12,14 @@ find_package(rosidl_default_generators REQUIRED) # further dependencies manually. # find_package( REQUIRED) +set(msg_files + "msg/StringLengthTest.msg" +) set(srv_files "srv/Huge.srv" ) rosidl_generate_interfaces(${PROJECT_NAME} + ${msg_files} ${srv_files} ADD_LINTER_TESTS ) diff --git a/prover_interfaces/msg/StringLengthTest.msg b/prover_interfaces/msg/StringLengthTest.msg new file mode 100644 index 0000000..c56869f --- /dev/null +++ b/prover_interfaces/msg/StringLengthTest.msg @@ -0,0 +1 @@ +string<=10 size_limited_string \ No newline at end of file diff --git a/prover_rclcpp/CMakeLists.txt b/prover_rclcpp/CMakeLists.txt index eaba976..962b431 100644 --- a/prover_rclcpp/CMakeLists.txt +++ b/prover_rclcpp/CMakeLists.txt @@ -37,6 +37,7 @@ find_package(rcutils) find_package(rmw REQUIRED) find_package(std_srvs REQUIRED) find_package(std_msgs REQUIRED) +find_package(prover_interfaces REQUIRED) find_package(example_interfaces REQUIRED) function(custom_executable target) @@ -45,6 +46,7 @@ function(custom_executable target) "rclcpp" "std_srvs" "std_msgs" + "prover_interfaces" "lifecycle_msgs" "rclcpp_lifecycle" "example_interfaces") @@ -82,6 +84,7 @@ custom_executable(rclcpp_1746) custom_executable(rclcpp_1766) custom_executable(rclcpp_1778) custom_executable(rclcpp_1785) +custom_executable(rclcpp_1827) custom_executable(rmw_fastrtps_554) custom_executable(rmw_fastrtps_555) diff --git a/prover_rclcpp/package.xml b/prover_rclcpp/package.xml index 5b7c8ea..dfbe6ba 100644 --- a/prover_rclcpp/package.xml +++ b/prover_rclcpp/package.xml @@ -22,6 +22,7 @@ rmw_implementation_cmake std_msgs std_srvs + prover_interfaces example_interfaces lifecycle_msgs @@ -32,7 +33,8 @@ rmw std_msgs std_srvs - example_interfaces + prover_interfaces + example_interfaces ament_cmake_pytest ament_lint_auto diff --git a/prover_rclcpp/src/rclcpp_1827.cpp b/prover_rclcpp/src/rclcpp_1827.cpp new file mode 100644 index 0000000..dac0eba --- /dev/null +++ b/prover_rclcpp/src/rclcpp_1827.cpp @@ -0,0 +1,38 @@ +#include +#include + +using namespace std::chrono_literals; + +#include "rclcpp/rclcpp.hpp" +#include "prover_interfaces/msg/string_length_test.hpp" + +class TestPublisher : public rclcpp::Node +{ + public: + TestPublisher() + : Node("string_length_test_publisher") + { + publisher_ = this->create_publisher("oversized", 10); + timer_ = this->create_wall_timer( + 1s, std::bind(&TestPublisher::timer_callback, this)); // 1kHz + } + + private: + void timer_callback() + { + auto message = prover_interfaces::msg::StringLengthTest(); + message.size_limited_string.resize(11, 'x'); + publisher_->publish(message); + } + rclcpp::TimerBase::SharedPtr timer_; + rclcpp::Publisher::SharedPtr publisher_; +}; + +int main(int argc, char **argv) +{ + rclcpp::init(argc, argv); + std::shared_ptr pub = std::make_shared(); + rclcpp::spin(pub); + rclcpp::shutdown(); + return 0; +}