Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-1936

bson_init_from_json() and bson_new_from_json() when provided with an empty string do not set error while returning false

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.6.0
    • None
    • json, libbson
    • None

    Description

      When called with an empty string, bson_init_from_json() and bson_new_from_json() do not set error leaving it uninitialized which produces inconsistency with the documentation and requires an extra check to be made on the calling side.

      Please refer to the following code snippet:

      #include <stdio.h>
      #include <bson.h>
       
      int main() {
      	bson_t bson;
      	bson_error_t error;
      	if (!bson_init_from_json(&bson, "", -1, &error)) {
      		printf("bson_init_from_json() failed: %s\n", error.message);
      		return 1;
      	}
      	bson_destroy(&bson);
      	return 0;
      }
      

      $ ./a.out
      bson_init_from_json() failed: �-T��
      

      Attachments

        Activity

          People

            jesse@mongodb.com A. Jesse Jiryu Davis
            neoxic Arseny Vakhrushev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: