Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7293

Useless/incorrect uassert in BSONElement constructor

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 2.0.7, 2.2.0
    • Component/s: Internal Code
    • None
    • ALL
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      In src/mongo/bson/bsonelement.h at line 439 in today's master branch, a uassert tests the return value from strnlen() for -1. This function cannot return -1 under any conceivable circumstances, so the test is useless.

              // @param maxLen don't scan more than maxLen bytes
              explicit BSONElement(const char *d, int maxLen) : data(d) {
                  if ( eoo() ) {
                      totalSize = 1;
                      fieldNameSize_ = 0;
                  }
                  else {
                      totalSize = -1;
                      fieldNameSize_ = -1;
                      if ( maxLen != -1 ) {
                          int size = (int) strnlen( fieldName(), maxLen - 1 );
                          uassert( 10333 ,  "Invalid field name", size != -1 );
                          fieldNameSize_ = size + 1;
                      }
                  }
              }
      

      The only way that strnlen() could return a value that when cast to int would be equal to -1 is if maxLen was zero and the "field name" consisted of 0xFFFFFFFF non-zero characters.

      The test should be removed or replaced with something more useful.

            Assignee:
            Unassigned Unassigned
            Reporter:
            tad Tad Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: