The following issues were found

src/mongo/bson/ugly_bson_integration_test.cpp
1 issues
syntax error
Error

Line: 53

                  }
};

TEST_F(UglyBSONFixture, DuplicateFields) {
    OpMsgBuilder::disableDupeFieldCheck_forTest.store(true);
    ON_BLOCK_EXIT([] { OpMsgBuilder::disableDupeFieldCheck_forTest.store(false); });

    assertCommandFailsOnServer("admin",
                               BSON("insert"

            

Reported by Cppcheck.

src/mongo/bson/util/bson_check_test.cpp
1 issues
syntax error
Error

Line: 47

              
const char* const legals[] = {"aField", "anotherField", "thirdField"};

TEST(BsonCheck, CheckHasOnlyOnEmptyObject) {
    ASSERT_OK(bsonCheckOnlyHasFields("", BSONObj(), legals));
}

TEST(BsonCheck, CheckHasOnlyLegalFields) {
    ASSERT_OK(bsonCheckOnlyHasFields("",

            

Reported by Cppcheck.

src/mongo/bson/util/bson_extract_test.cpp
1 issues
Shifting by a negative value is undefined behaviour
Error

Line: 146 CWE codes: 758

                  ASSERT_OK(bsonExtractIntegerFieldWithDefaultIf(BSON("a" << 1), "a", -1LL, pred, &v));
    ASSERT_OK(bsonExtractIntegerFieldWithDefaultIf(BSON("a" << 1), "b", 1LL, pred, &v));
    auto msg = "'a' has to be greater than zero";
    auto status = bsonExtractIntegerFieldWithDefaultIf(BSON("a" << -1), "a", 1LL, pred, msg, &v);
    ASSERT_EQUALS(ErrorCodes::BadValue, status);
    ASSERT_STRING_CONTAINS(status.reason(), msg);
    ASSERT_EQUALS(ErrorCodes::BadValue,
                  bsonExtractIntegerFieldWithDefaultIf(BSON("a" << 1), "b", -1LL, pred, &v));
}

            

Reported by Cppcheck.

src/mongo/bson/util/bsoncolumn_test.cpp
1 issues
syntax error
Error

Line: 311

                  std::forward_list<BSONObj> _elementMemory;
};

TEST_F(BSONColumnTest, BasicValue) {
    BSONColumnBuilder cb("test"_sd);

    auto elem = createElementInt32(1);
    cb.append(elem);
    cb.append(elem);

            

Reported by Cppcheck.

src/mongo/bson/util/bsoncolumnbuilder.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 354 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

              
    // Copy element into buffer for previous. Omit field name.
    _prev[0] = elem.type();
    memcpy(_prev.get() + 2, elem.value(), valuesize);
    _prevSize = size;
}

void BSONColumnBuilder::_writeLiteralFromPrevious() {
    // Write literal without field name and reset control byte to force new one to be written when

            

Reported by FlawFinder.

src/mongo/bson/util/builder_test.cpp
1 issues
syntax error
Error

Line: 47

                  ASSERT_EQUALS(0, strcmp("eliot", bb.buf()));
}

TEST(Builder, StringBuilderAddress) {
    const void* longPtr = reinterpret_cast<const void*>(-1);
    const void* shortPtr = reinterpret_cast<const void*>(static_cast<uintptr_t>(0xDEADBEEF));

    const void* nullPtr = nullptr;


            

Reported by Cppcheck.

src/mongo/client/authenticate_test.cpp
1 issues
syntax error
Error

Line: 171

                  std::queue<BSONObj> _responses;
};

TEST_F(AuthClientTest, MongoCR) {
    // This test excludes the MONGODB-CR support found in mongo/shell/mongodbcr.cpp
    // so it should fail to auth.
    // jstests exist to ensure MONGODB-CR continues to work from the client.
    auto params = loadMongoCRConversation();
    ASSERT_THROWS(

            

Reported by Cppcheck.

src/mongo/client/connection_string_test.cpp
1 issues
syntax error
Error

Line: 41

              
using unittest::assertGet;

TEST(ConnectionString, EqualityOperatorStandalone) {
    const auto cs = assertGet(ConnectionString::parse("TestHostA:12345"));
    ASSERT(cs == assertGet(ConnectionString::parse("TestHostA:12345")));
    ASSERT_FALSE(cs != assertGet(ConnectionString::parse("TestHostA:12345")));
    ASSERT(cs != assertGet(ConnectionString::parse("TestHostB:12345")));
    ASSERT_FALSE(cs == assertGet(ConnectionString::parse("TestHostB:12345")));

            

Reported by Cppcheck.

src/mongo/client/connpool_integration_test.cpp
1 issues
syntax error
Error

Line: 99

                  pool.release(host, conn1);
}

TEST(ConnectionPoolTest, ConnectionPoolMaxInUseTimeoutTest) {
    DBConnectionPool pool;

    auto fixture = unittest::getFixtureConnectionString();
    auto host = fixture.getServers()[0].toString();


            

Reported by Cppcheck.

src/mongo/client/dbclient_connection_integration_test.cpp
1 issues
syntax error
Error

Line: 82

                  }
};

TEST_F(DBClientConnectionFixture, shutdownWorksIfCalledFirst) {
    auto conn = makeConn();

    conn->shutdownAndDisallowReconnect();

    BSONObj reply;

            

Reported by Cppcheck.