[CDRIVER-1533] mongoc_client_get_server_descriptions can return NULLs Created: 08/Sep/16  Updated: 20/Sep/16  Resolved: 09/Sep/16

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.4.0
Fix Version/s: 1.4.1, 1.5.0

Type: Bug Priority: Critical - P2
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

Issue Links:
Related
is related to CDRIVER-1091 mongoc_client_get_server_descriptions() Closed

 Description   

The 1.4.0 function mongoc_client_get_server_descriptions is supposed to return an array of server description pointers and the number of pointers, "n". It omits server descriptions of "unknown" type.

But, instead of tightly packing pointers to known-type server descriptions, it instead leaves NULL pointers in the returned array. For example, if there are 2 known servers and 1 unknown server, mongoc_client_get_server_descriptions is supposed to return:

[known server, known server, NULL]
n=2

... instead, it returns:

[known server, NULL, known server]
n=2

This could crash the caller, which doesn't expect any NULLs. If the caller doesn't crash, it still gets incorrect results, because n=2 is supposed to mean that the first two array elements are server description pointers. If the caller gets far enough to call mongoc_server_descriptions_destroy_all, it will crash there.

The unreleased new 1.5.0 function mongoc_topology_description_get_servers has the same bug.



 Comments   
Comment by Githook User [ 20/Sep/16 ]

Author:

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

Message: CDRIVER-1533 omit NULLs from mongoc_client_get_server_descriptions
Branch: r1.4
https://github.com/mongodb/mongo-c-driver/commit/709a7dc0631633e9c9fa6ae84d867309abdefd35

Comment by Githook User [ 09/Sep/16 ]

Author:

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

Message: CDRIVER-1533 omit NULLs from mongoc_topology_description_get_servers
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a4bcfffa9c7ffa2e541a3351ec26cfad417cbdcf

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