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

Correctly initialize defaulted external sequence #1956

Merged
merged 2 commits into from Mar 28, 2024

Conversation

eboasson
Copy link
Contributor

An external mutable struct containing a sequence member that for which no value is
provided by the CDR was not initialized correctly: only the length field was set to 0, not
the other fields. If the _release field happens to be false, this is harmless; if not it
results in freeing of unallocated memory.

An external mutable struct containing a sequence member that for which no value is
provided by the CDR was not initialized correctly: only the length field was set to 0, not
the other fields.  If the _release field happens to be false, this is harmless; if not it
results in freeing of unallocated memory.

Signed-off-by: Erik Boasson <eb@ilities.com>
{
seq->_buffer = NULL;
seq->_maximum = 0;
seq->_release = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be set to false. Seems that this could result in freeing a NULL pointer in src/core/cdr/src/dds_cdrstream.c:3283, but that won't do any harm in current allocators.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first I wrote initialization code at line 1958 (or thereabouts) and wondered about how to initialise _release. Then I realised I could refactor things and have a single implementation. The true is simply what it used to do. Therefore I am tempted to leave it as-is in this PR.

This test relies on the combination of the address sanitizer and the undefined behaviour
sanitizer: the former for initializing freshly allocated memory, the latter for faulting
on trying to load `bool` from memory with a value other than 0 or 1.

Signed-off-by: Erik Boasson <eb@ilities.com>
@eboasson eboasson merged commit 085bd87 into eclipse-cyclonedds:master Mar 28, 2024
1 check passed
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

2 participants