<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:08:57 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[MONGOCRYPT-559] _fle2_mongo_op_markings and _create_markings_cmd_bson are double-initializing bson_t&#8217;s</title>
                <link>https://jira.mongodb.org/browse/MONGOCRYPT-559</link>
                <project id="17481" key="MONGOCRYPT">Libmongocrypt</project>
                    <description>&lt;p&gt;In &lt;tt&gt;mongocrypt-ctx-encrypt.c&lt;/tt&gt;, a Valgrind memory leak can occur when the libbson &lt;tt&gt;BSON_MEMCHECK&lt;/tt&gt; compile flag is set in two possible ways.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;tt&gt;bson_init&lt;/tt&gt; and &lt;tt&gt;bson_init_static&lt;/tt&gt; on same &lt;tt&gt;bson_t&lt;/tt&gt; instance
	&lt;ul&gt;
		&lt;li&gt;In &lt;tt&gt;_fle2_mongo_op_markings&lt;/tt&gt;, &lt;tt&gt;bson_t cmd_bson&lt;/tt&gt; and &lt;tt&gt;encrypted_field_config_bson&lt;/tt&gt; is initialized on &lt;a href=&quot;https://github.com/mongodb/libmongocrypt/blob/2ec9c3c4ff94f76bb51a5b4cc2fe9190457d6541/src/mongocrypt-ctx-encrypt.c#L627C3-L628&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;lines 627&#8211;628 (as of commit 2ec9c3)&lt;/a&gt;. Then, &lt;tt&gt;cmd_bson&lt;/tt&gt; and &lt;tt&gt;encrypted_field_config_bson&lt;/tt&gt; are passed as the &lt;tt&gt;bson&lt;/tt&gt; argument to &lt;tt&gt;_mongocrypt_buffer_to_bson&lt;/tt&gt;, which double-initializes the input &lt;tt&gt;bson&lt;/tt&gt; with &lt;tt&gt;bson_init_static&lt;/tt&gt;.
		&lt;ul&gt;
			&lt;li&gt;This can be fixed by removing &lt;tt&gt;BSON_INITIALIZER&lt;/tt&gt; from the declaration of &lt;tt&gt;cmd_bson&lt;/tt&gt; and &lt;tt&gt;encrypted_field_config_bson&lt;/tt&gt;.&lt;/li&gt;
		&lt;/ul&gt;
		&lt;/li&gt;
		&lt;li&gt;Similarly, in &lt;tt&gt;_create_markings_cmd_bson&lt;/tt&gt;, &lt;tt&gt;bson_t bson_view&lt;/tt&gt; is initialized on &lt;a href=&quot;https://github.com/mongodb/libmongocrypt/blob/2ec9c3c4ff94f76bb51a5b4cc2fe9190457d6541/src/mongocrypt-ctx-encrypt.c#L696-L697&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;line 696&lt;/a&gt; and is passed to &lt;tt&gt;_mongocrypt_buffer_to_bson&lt;/tt&gt;, which double-initializes &lt;tt&gt;bson_view&lt;/tt&gt;.
		&lt;ul&gt;
			&lt;li&gt;This can be fixed by removing &lt;tt&gt;BSON_INITIALIZER&lt;/tt&gt; from the declaration of &lt;tt&gt;bson_view&lt;/tt&gt;.&lt;/li&gt;
		&lt;/ul&gt;
		&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;bson_init&lt;/tt&gt; twice on same &lt;tt&gt;bson_t&lt;/tt&gt;
	&lt;ul&gt;
		&lt;li&gt;Another double-init issue can occur as callers of &lt;tt&gt;_create_markings_cmd_bson&lt;/tt&gt; pass their &lt;tt&gt;out&lt;/tt&gt; argument as already-initialized (see &lt;a href=&quot;https://github.com/mongodb/libmongocrypt/blob/master/src/mongocrypt-ctx-encrypt.c#L751-L757&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;this example&lt;/a&gt;). Then, there are two possible ways the &lt;tt&gt;out&lt;/tt&gt; argument can be initialized again within the scope of &lt;tt&gt;_create_markings_cmd_bson&lt;/tt&gt;:
		&lt;ul&gt;
			&lt;li&gt;For an FLE1 command, it calls &lt;tt&gt;bson_init&lt;/tt&gt; on &lt;a href=&quot;https://github.com/mongodb/libmongocrypt/blob/master/src/mongocrypt-ctx-encrypt.c#L706&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;line 706&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;For an FLE2 command, the processing of the command gets passed to &lt;tt&gt;_fle2_mongo_op_markings&lt;/tt&gt; which calls &lt;tt&gt;bson_init&lt;/tt&gt; on &lt;tt&gt;out&lt;/tt&gt; on &lt;a href=&quot;https://github.com/mongodb/libmongocrypt/blob/2ec9c3c4ff94f76bb51a5b4cc2fe9190457d6541/src/mongocrypt-ctx-encrypt.c#L654&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;line 654&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
		&lt;/li&gt;
		&lt;li&gt;To fix this issue, the calls to &lt;tt&gt;bson_init&lt;/tt&gt; on 654 and 706 can be removed since the callers of &lt;tt&gt;_create_markings_cmd_bson&lt;/tt&gt; are already initializing the input &lt;tt&gt;bson_t&lt;/tt&gt; structure.&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;&#8212;&lt;/p&gt;

&lt;p&gt;To reproduce the memory leak, use&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: #ff1493; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;mkdir&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; cmake-build &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #ff1493; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;cd&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; cmake-build&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;cmake ../&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: #ff1493; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;make&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;valgrind --leak-check=full .&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;/test-mongocrypt&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</description>
                <environment></environment>
        <key id="2285751">MONGOCRYPT-559</key>
            <summary>_fle2_mongo_op_markings and _create_markings_cmd_bson are double-initializing bson_t&#8217;s</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="kyle.kloberdanz@mongodb.com">Kyle Kloberdanz</assignee>
                                    <reporter username="zachary.espiritu@mongodb.com">Zachary Espiritu</reporter>
                        <labels>
                    </labels>
                <created>Fri, 10 Mar 2023 15:50:16 +0000</created>
                <updated>Thu, 27 Apr 2023 19:22:56 +0000</updated>
                            <resolved>Thu, 27 Apr 2023 19:22:56 +0000</resolved>
                                                    <fixVersion>1.8.0</fixVersion>
                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="5382426" author="xgen-internal-githook" created="Thu, 27 Apr 2023 19:22:10 +0000"  >&lt;p&gt;Author: &lt;/p&gt;
{&apos;name&apos;: &apos;Kyle Kloberdanz&apos;, &apos;email&apos;: &apos;kyle.kloberdanz@mongodb.com&apos;, &apos;username&apos;: &apos;kkloberdanz&apos;}
&lt;p&gt;Message: Improve bson_t initialization behavior (#629)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/MONGOCRYPT-558&quot; title=&quot;FLE2RangeFindDriverSpec_to_ciphertexts leads to double-initializing bson_t&quot; class=&quot;issue-link&quot; data-issue-key=&quot;MONGOCRYPT-558&quot;&gt;&lt;del&gt;MONGOCRYPT-558&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;https://jira.mongodb.org/browse/MONGOCRYPT-559&quot; title=&quot;_fle2_mongo_op_markings and _create_markings_cmd_bson are double-initializing bson_t&#8217;s&quot; class=&quot;issue-link&quot; data-issue-key=&quot;MONGOCRYPT-559&quot;&gt;&lt;del&gt;MONGOCRYPT-559&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;https://jira.mongodb.org/browse/MONGOCRYPT-560&quot; title=&quot;_fle2_insert_encryptionInformation raises Valgrind errors on bson_t&quot; class=&quot;issue-link&quot; data-issue-key=&quot;MONGOCRYPT-560&quot;&gt;&lt;del&gt;MONGOCRYPT-560&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This addresses the issues brought up in the above tickets. We will not be removing calls to `BSON_INITIALIZER`, but we are addressing the other issues uncovered in these tickets.&lt;/p&gt;

&lt;p&gt;Co-authored-by: Kevin Albertson &amp;lt;kevin.albertson@10gen.com&amp;gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/libmongocrypt/commit/ec15461d69cd740d9b8b5f195fc920a2347005dd&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/libmongocrypt/commit/ec15461d69cd740d9b8b5f195fc920a2347005dd&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="5374915" author="JIRAUSER1271575" created="Tue, 25 Apr 2023 19:14:06 +0000"  >&lt;p&gt;Hello Zachary, thank you for reporting this.&lt;/p&gt;

&lt;p&gt;I&apos;ve made sure to clean up several of these issues, and I&apos;ll have a PR with the fixes ready soon. However, we prefer to not remove these calls to BSON_INITIALIZER. Since we do not use BSON_MEMCHECK, initializing a bson object with BSON_INITIALIZER doesn&apos;t cause us an issue, and it makes the code more robust since it avoids dealing with uninitialized objects.&lt;/p&gt;

&lt;p&gt;Please also see &lt;a href=&quot;https://jira.mongodb.org/browse/MONGOCRYPT-554?focusedCommentId=5271352&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-5271352&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;Kevin&apos;s response&lt;/a&gt; on another ticket.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                <customfield id="customfield_21957" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Binding Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="22966"><![CDATA[Not Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr6i7r:f0whr</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                </customfields>
    </item>
</channel>
</rss>