Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4420

bson_error_t message shows garbage in some cases

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Unknown 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)

      {       HX2A_LOG(error) << "Cannot get MongoDB databases list for database identifier \"" << db_id << "\". Got error message \"" << error.message << "\".";       throw request_rollback(); }

      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). 

      Attachments

        Activity

          People

            ezra.chung@mongodb.com Ezra Chung
            josephcanedo@gmail.com Joseph Canedo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: