[CDRIVER-1043] bson_strnlen is off by one Created: 09/Dec/15  Updated: 18/Jan/16  Resolved: 09/Dec/15

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

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


 Description   

bson_strnlen returns strnlen if available, otherwise a custom implementation of strnlen. Ever since it was first written, bson_strnlen's custom implementation has returned a value 1 greater than strnlen.

Furthermore, due to a misspelled ifdef (CDRIVER-1041), bson_strnlen always uses its custom implementation instead of using strnlen when available.

This was undetected because:

1. bson_strnlen is not directly tested
2. It was only used in _mongoc_ssl_check_cert to check if a hostname has internal nils: bson_strnlen (name, name_length). Since the max length was already calculated, the off-by-one error had no effect.
3. I mistakenly used standard strnlen instead of bson_strnlen in new cursor code (also reported in CDRIVER-1041).



 Comments   
Comment by Githook User [ 09/Dec/15 ]

Author:

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

Message: CDRIVER-1043 bson_strnlen is off by one
Branch: master
https://github.com/mongodb/libbson/commit/12750146601dff97493675e4d4b85a7d5c03d6e1

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