From 4c560f81463741051a041458fa2c36b3712c430c Mon Sep 17 00:00:00 2001 From: Abby Xu Date: Wed, 1 May 2019 15:12:52 -0700 Subject: [PATCH] fix buffer overflow in test_security_dir 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 3b054a317..9ac2f9259 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