[CDRIVER-381] libbson: bson_as_json returns incorrect length for empty object Created: 19/Jun/14  Updated: 20/Jun/14  Resolved: 20/Jun/14

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 0.96.4

Type: Bug Priority: Major - P3
Reporter: Itay Neeman Assignee: Christian Hergert
Resolution: Done Votes: 0
Labels: bson
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The bson_as_json function has a shortcut for an empty object, which has this code:

   if (bson_empty0 (bson)) {
      if (length) {
         *length = 2;
      }
 
      return bson_strdup ("{ }");
   }

https://github.com/mongodb/libbson/blob/master/src/bson/bson.c#L2672

As you can see, the returned string is three characters long, but we only return 2 as the output length. It should be 3.



 Comments   
Comment by Christian Hergert [ 20/Jun/14 ]

Yeah, as long as everything goes smooth. I want to release a bunch of RPMs, DEBs, SRV4, and Win32 packages which could take some time.

Comment by Itay Neeman [ 20/Jun/14 ]

Thanks - are we still on track for a release today?

Comment by Christian Hergert [ 20/Jun/14 ]

Fixed in https://github.com/mongodb/libbson/commit/1f514ad5196f6d5fec48705a398b897a5d357ae5

Thanks again!

Comment by Christian Hergert [ 20/Jun/14 ]

Thanks! I'll fix this and update the JSON array formatting at the same time.

Cheers,

Comment by David Hows [ 19/Jun/14 ]

Hi Itay,

This looks like a clear bug. I've moved it over to the C Driver project to be addressed directly.

As ever, thank you so much for taking the time to report this!

Comment by Itay Neeman [ 19/Jun/14 ]

christian.hergert FYI for this bug.

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