From d947655a532e8f607d788c25dd22db2f43ee6935 Mon Sep 17 00:00:00 2001 From: Abby Xu <30247381+xabxx@users.noreply.github.com> Date: Thu, 2 May 2019 12:45:51 -0700 Subject: [PATCH] fix buffer overflow in test_security_dir (#423) Signed-off-by: Abby Xu --- rcl/test/rcl/test_security_directory.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rcl/test/rcl/test_security_directory.cpp b/rcl/test/rcl/test_security_directory.cpp index 3b054a3..9ac2f92 100644 --- a/rcl/test/rcl/test_security_directory.cpp +++ b/rcl/test/rcl/test_security_directory.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "rcl/security_directory.h" #include "rcutils/filesystem.h" @@ -109,7 +110,8 @@ TEST_F(TestGetSecureRoot, successScenarios) { TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME, allocator); std::string putenv_input = ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "="; putenv_input += base_lookup_dir_fqn; - memcpy(g_envstring, putenv_input.c_str(), sizeof(g_envstring) - 1); + memcpy(g_envstring, putenv_input.c_str(), + std::min(putenv_input.length(), sizeof(g_envstring) - 1)); putenv_wrapper(g_envstring); /* -------------------------- * Namespace : Root