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

Check allocator validity in some rcl_logging functions #116

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

cottsay
Copy link
Member

@cottsay cottsay commented Mar 6, 2024

If the allocator is zero-initialized, it may cause a segfault when it is used later in the function. Right now, we're relying on other rcutils_* functions which use the allocator to fail before we attempt to use it directly, but just because the allocator is passed to these functions doesn't always mean that it is used, especially when the program flow can change based on things like environment variables.

@cottsay cottsay self-assigned this Mar 6, 2024
@@ -100,6 +100,8 @@ rcl_logging_ret_t rcl_logging_external_initialize(
const char * config_file,
rcutils_allocator_t allocator)
{
RCUTILS_CHECK_ALLOCATOR(&allocator, return RCL_LOGGING_RET_ERROR);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that an "invalid argument" return code would be more appropriate, but this error code has already been established for at least some cases of an invalid allocator.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same check can be applied to rcl_logging_get_logging_directory as a function scope?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that an "invalid argument" return code would be more appropriate, but this error code has already been established for at least some cases of an invalid allocator.

Doing a quick grep for RCUTILS_CHECK_ALLOCATOR through our codebase, it looks like we most often use INVALID_ARGUMENT as the return value. So I'd suggest that we switch to that here, as well as update the documentation for rcl_logging_external_initialize to say that it is a possible return code.

the same check can be applied to rcl_logging_get_logging_directory as a function scope?

Yeah, I think that is a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so we're clear: this will technically be an API break as is demonstrated by the need to update the test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so we're clear: this will technically be an API break as is demonstrated by the need to update the test.

Yeah, I think that is OK here. This is a really low-level function, and I don't really expect anything outside of rcl to be calling it. Indeed, looking through all of the packages released into Rolling, nothing else calls it.

I also looked through some external rcl* packages:

  • ros2-rust - doesn't use it
  • ros2-java - doesn't use it
  • ada-ros - does use it, but since the repo hasn't been updated in 3 years I think there will be other breakage as well
  • r2r - doesn't use it
  • rclc - doesn't use it
  • rclnodejs - doesn't use it

I also did a full search on GitHub for it, and while there are a few more uses of it, I don't think anything catastrophic is going to happen if we add this return code here.

@cottsay cottsay mentioned this pull request Mar 6, 2024
If the allocator is zero-initialized, it may cause a segfault when it is
used later in the functions.

Signed-off-by: Scott K Logan <logans@cottsay.net>
@cottsay cottsay changed the title Check allocator validity in rcl_logging_external_initialize Check allocator validity in some rcl_logging functions Mar 6, 2024
Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@cottsay
Copy link
Member Author

cottsay commented Mar 6, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

The one thing I'm going to suggest here is that we run tests --packages-above rcl_logging_interface rcl_logging_spdlog. While my look above suggested that we won't have a problem, I think we should double check via CI before merging.

@cottsay
Copy link
Member Author

cottsay commented Mar 6, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@cottsay cottsay merged commit 133884b into rolling Mar 7, 2024
2 of 3 checks passed
@delete-merged-branch delete-merged-branch bot deleted the cottsay/allocator-check branch March 7, 2024 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants