[MONGOCRYPT-560] _fle2_insert_encryptionInformation raises Valgrind errors on bson_t Created: 11/Mar/23  Updated: 27/Apr/23  Resolved: 27/Apr/23

Status: Closed
Project: Libmongocrypt
Component/s: None
Affects Version/s: None
Fix Version/s: 1.8.0

Type: Bug Priority: Unknown
Reporter: Zachary Espiritu Assignee: Kyle Kloberdanz
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Binding Changes: Not Needed

 Description   

In _fle2_insert_encryptionInformation in mongocrypt-ctx-encrypt.c, a Valgrind memory leak can occur when the libbson BSON_MEMCHECK compile flag is set because:

  1. bson_t explain is initialized on line 222 (as of commit 073a95) but is then passed as the dst argument to bson_copy_to on line 275 which requires that dst be uninitialized to avoid leaking memory (documentation)
  2. bson_t out is initialized on line 221, but if the goto success statement on line 246 is hit, then out never gets bson_destroy-ed before the function exits


 Comments   
Comment by Githook User [ 27/Apr/23 ]

Author:

{'name': 'Kyle Kloberdanz', 'email': 'kyle.kloberdanz@mongodb.com', 'username': 'kkloberdanz'}

Message: Improve bson_t initialization behavior (#629)

MONGOCRYPT-558
MONGOCRYPT-559
MONGOCRYPT-560

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.

Co-authored-by: Kevin Albertson <kevin.albertson@10gen.com>
Branch: master
https://github.com/mongodb/libmongocrypt/commit/ec15461d69cd740d9b8b5f195fc920a2347005dd

Generated at Thu Feb 08 09:08:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.