Fix UB in accessing the keys (backport #879)#883
Merged
clalancette merged 1 commit intokiltedfrom May 5, 2026
Merged
Conversation
* Make sure to do key.resize() Doing a key.reserve() allocates memory, but still leaves the size at 0. Thus an access with the [] operator is UB. This came up on Ubuntu 26.04 because it is more strict about UB. Fix it by using resize() instead, which does increase the size and thus the [] operator is no longer UB. Signed-off-by: Chris Lalancette <clalancette@gmail.com> * rmw_fastrtps_dynamic_cpp: Fix a UB in key support. The problem here is that we were always accessing 16 bytes of data from the key buffer, even when it was shorter than that. What we do instead is to always set the ihandle->value to all zeros, then only copy in the number of key_buffer bytes we have. This matches what rmw_fastrtps_cpp does, and fixes a crash in tests on Ubuntu 26.04 Signed-off-by: Chris Lalancette <clalancette@gmail.com> --------- Signed-off-by: Chris Lalancette <clalancette@gmail.com> (cherry picked from commit eb15778)
Contributor
Contributor
|
Current Windows CI for Kilted is not working (confirmed today at the ROS 2 PMC meeting), so I'm going ahead and merging this one in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This fixes two different problems with respect to keys:
Doing a key.reserve() allocates memory, but still
leaves the size at 0. Thus an access with the []
operator is UB. This came up on Ubuntu 26.04 because
it is more strict about UB.
Fix it by using resize() instead, which does increase
the size and thus the [] operator is no longer UB.
The problem here is that we were always accessing 16 bytes
of data from the key buffer, even when it was shorter than
that. What we do instead is to always set the ihandle->value
to all zeros, then only copy in the number of key_buffer
bytes we have. This matches what rmw_fastrtps_cpp does,
and fixes a crash in tests on Ubuntu 26.04
This should be merged at approximately the same time as #880 , #881 , and ros2/system_tests#592
Is this user-facing behavior change?
No.
Did you use Generative AI?
Yes, Claude Opus 4.7
Additional Information
This should be backported to Lyrical and Kilted.
This is an automatic backport of pull request #879 done by Mergify.