Skip to content

Commit d947655

Browse files
xabxxsloretz
authored andcommitted
fix buffer overflow in test_security_dir (#423)
Signed-off-by: Abby Xu <[email protected]>
1 parent 3d48555 commit d947655

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

rcl/test/rcl/test_security_directory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <gtest/gtest.h>
1616

1717
#include <string>
18+
#include <algorithm>
1819
#include "rcl/security_directory.h"
1920
#include "rcutils/filesystem.h"
2021

@@ -109,7 +110,8 @@ TEST_F(TestGetSecureRoot, successScenarios) {
109110
TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME, allocator);
110111
std::string putenv_input = ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "=";
111112
putenv_input += base_lookup_dir_fqn;
112-
memcpy(g_envstring, putenv_input.c_str(), sizeof(g_envstring) - 1);
113+
memcpy(g_envstring, putenv_input.c_str(),
114+
std::min(putenv_input.length(), sizeof(g_envstring) - 1));
113115
putenv_wrapper(g_envstring);
114116
/* --------------------------
115117
* Namespace : Root

0 commit comments

Comments
 (0)