Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix security directory lookup for '/' security contexts #609

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rcl/src/rcl/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ char * exact_match_lookup(
{
// Perform an exact match for the context name in directory <root dir>.
char * secure_root = NULL;
char * contexts_dir = NULL;
contexts_dir = rcutils_join_path(ros_secure_root_env, "contexts", *allocator);
// "/" case when root namespace is explicitly passed in
if (0 == strcmp(name, "/")) {
secure_root = rcutils_strdup(ros_secure_root_env, *allocator);
secure_root = contexts_dir;
} else {
char * relative_path = NULL;
char * contexts_dir = NULL;
// Get native path, ignore the leading forward slash
// TODO(ros2team): remove the hard-coded length, use the length of the root namespace instead
relative_path = rcutils_to_native_path(name + 1, *allocator);
contexts_dir = rcutils_join_path(ros_secure_root_env, "contexts", *allocator);
secure_root = rcutils_join_path(contexts_dir, relative_path, *allocator);
allocator->deallocate(relative_path, allocator->state);
allocator->deallocate(contexts_dir, allocator->state);
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
12 changes: 12 additions & 0 deletions rcl/test/rcl/test_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ TEST_F(TestGetSecureRoot, failureScenarios) {
rcl_reset_error();
}

TEST_F(TestGetSecureRoot, successScenarios_local_root_security_context) {
putenv_wrapper(
ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "="
TEST_RESOURCES_DIRECTORY TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME);

secure_root = rcl_get_secure_root("/", &allocator);
ASSERT_NE(nullptr, secure_root);
ASSERT_STREQ(
TEST_RESOURCES_DIRECTORY TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME PATH_SEPARATOR "contexts",
secure_root);
}

TEST_F(TestGetSecureRoot, successScenarios_local_exactMatch) {
putenv_wrapper(
ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "="
Expand Down