Skip to content

Fix UB in accessing the keys (backport #879)#883

Merged
clalancette merged 1 commit intokiltedfrom
mergify/bp/kilted/pr-879
May 5, 2026
Merged

Fix UB in accessing the keys (backport #879)#883
clalancette merged 1 commit intokiltedfrom
mergify/bp/kilted/pr-879

Conversation

@mergify
Copy link
Copy Markdown

@mergify mergify Bot commented May 3, 2026

Description

This fixes two different problems with respect to keys:

  • 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.

  • 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

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.

* 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)
@mergify mergify Bot mentioned this pull request May 3, 2026
@clalancette
Copy link
Copy Markdown
Contributor

CI:

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

@clalancette
Copy link
Copy Markdown
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.

@clalancette clalancette merged commit 4232726 into kilted May 5, 2026
3 checks passed
@clalancette clalancette deleted the mergify/bp/kilted/pr-879 branch May 5, 2026 19:39
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.

1 participant