Skip to content

CDRIVER-5536 zero-init bson_iter_t::value #1587

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

Merged
merged 1 commit into from
May 1, 2024
Merged

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Apr 30, 2024

Summary

Zero-initialize bson_iter_t::value.

This PR is related to, but does not resolve CDRIVER-5536.

Background & Motivation

There are many Coverity issues in the libmongocrypt project referencing uninitialized access of the bson_iter_t::value field:

bson_iter_t iter1;
BSON_ASSERT (bson_iter_init (&iter1, &bson)); // Does not initialize `iter1.value`
bson_iter_t iter2 = iter1; // Assigns uninitialized `value`.

I expect this is OK in practice. I do not expect bson_iter_t::value is meant to be directly accessed. The bson_iter_t::value is initialized and returned in bson_iter_value. Regardless, this PR errs towards safety. A caller may reasonably expect bson_iter_init to initialize all struct fields.

Intended to address repeated warnings from Coverity. Though leaving `value` uninitialized may be safe, it is also a public struct field.
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

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

LGTM

@kevinAlbs kevinAlbs merged commit 51de955 into mongodb:master May 1, 2024
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.

2 participants