Uploaded image for project: 'Libmongocrypt'
  1. Libmongocrypt
  2. MONGOCRYPT-558

FLE2RangeFindDriverSpec_to_ciphertexts leads to double-initializing bson_t

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • 1.8.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed

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

      • bson_t with_placholders is initialized on line 1730 (as of commit 2ec9c3) with BSON_INITIALIZER
      • The function calls mc_FLE2RangeFindDriverSpec_to_placeholders on line 1768 and passes with_placholders as the out argument.
      • mc_FLE2RangeFindDriverSpec_to_placeholders calls bson_init on out on line 508

      One possible solution is to remove the extra call to bson_init within the mc_FLE2RangeFindDriverSpec_to_placeholders function. Note that there is a test case in test-mc-fle2-rfds.c that uses mc_FLE2RangeFindDriverSpec_to_placeholders and the out argument passed to that test function will need to be initialized if this change is made.

      To reproduce the memory leak, use

      mkdir cmake-build && cd cmake-build
      cmake ../
      make
      valgrind --leak-check=full ./test-mongocrypt 
      

            Assignee:
            kyle.kloberdanz@mongodb.com Kyle Kloberdanz (Inactive)
            Reporter:
            zachary.espiritu@mongodb.com Zachary Espiritu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: