Details
-
Bug
-
Resolution: Works as Designed
-
Unknown
-
None
-
None
-
None
-
None
Description
Summary
In some cases printing bson_error_t message outputs garbage characters. For example: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling hello on '127.0.0.1:27017']�
r��Ux
_r��U u���U`u���U�㰕�U�㰕�U�;ܖ�U�=ܖ�U�;ܖ�U�;ܖ�U�=ܖ�U�=ܖ�U���l^Jy����������l^Jy������������������������������������������l^Jy����������l^Jy��������K��_
__���U�;ܖ�UX9ܖ�UL��h9ܖ�U0L��`L���X���UpL��89ܖ�UPL��p<ܖ�UpL���L���X���U�kg��U89ܖ�Up<ܖ�U"._
Environment
C driver 1.22.0
Linux Ubuntu 22.10
gcc 12.1
MongoDB server 5.0.9
How to Reproduce
Happens for example with following code without MongoDB running.
char **strv = mongoc_client_get_database_names_with_opts(_client, nullptr, &error);
if (!strv)
Additional Background
Suspect that setting null char does not happen in correct position in message string in bson_set_error function.
error->message[sizeof error->message - 1] = '\0';
Should set at whatever position after last char bson_vsnprintf writes (with check it does not overflow message buffer of course).