[CDRIVER-1936] bson_init_from_json() and bson_new_from_json() when provided with an empty string do not set error while returning false Created: 25/Nov/16  Updated: 07/Jan/17  Resolved: 07/Jan/17

Status: Closed
Project: C Driver
Component/s: json, libbson
Affects Version/s: None
Fix Version/s: 1.6.0

Type: Bug Priority: Major - P3
Reporter: Arseny Vakhrushev Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File libbson1.c    

 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��



 Comments   
Comment by Githook User [ 07/Jan/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1936 set error when parsing empty JSON
Branch: master
https://github.com/mongodb/libbson/commit/1657419797ae29e1c8412e6f030b49d72858c948

Comment by A. Jesse Jiryu Davis [ 25/Nov/16 ]

Thanks for the report!

Generated at Wed Feb 07 21:13:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.