The following issues were found

src/mongo/db/s/balancer/cluster_statistics_impl.h
1 issues
random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 44 Column: 49 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

               */
class ClusterStatisticsImpl final : public ClusterStatistics {
public:
    ClusterStatisticsImpl(BalancerRandomSource& random);
    ~ClusterStatisticsImpl();

    StatusWith<std::vector<ShardStatistics>> getStats(OperationContext* opCtx) override;

private:

            

Reported by FlawFinder.

src/mongo/db/s/balancer/cluster_statistics_test.cpp
1 issues
syntax error
Error

Line: 42

              
const auto emptyTagSet = std::set<std::string>();

TEST(ShardStatistics, SizeMaxedTest) {
    ASSERT(
        !ShardStatistics(ShardId("TestShardId"), 0, 0, false, emptyTagSet, "3.2.0").isSizeMaxed());
    ASSERT(!ShardStatistics(ShardId("TestShardId"), 100LL, 80LL, false, emptyTagSet, "3.2.0")
                .isSizeMaxed());
    ASSERT(ShardStatistics(ShardId("TestShardId"), 100LL, 110LL, false, emptyTagSet, "3.2.0")

            

Reported by Cppcheck.

src/mongo/db/s/balancer/migration_manager_test.cpp
1 issues
syntax error
Error

Line: 108

                  ReadWriteConcernDefaultsLookupMock _lookupMock;
};

TEST_F(MigrationManagerTest, OneCollectionTwoMigrations) {
    // Set up two shards in the metadata.
    ASSERT_OK(catalogClient()->insertConfigDocument(
        operationContext(), ShardType::ConfigNS, kShard0, kMajorityWriteConcern));
    ASSERT_OK(catalogClient()->insertConfigDocument(
        operationContext(), ShardType::ConfigNS, kShard2, kMajorityWriteConcern));

            

Reported by Cppcheck.

src/mongo/db/s/balancer/scoped_migration_request_test.cpp
1 issues
syntax error
Error

Line: 118

                                     MigrateInfo::chunksImbalance);
}

TEST_F(ScopedMigrationRequestTest, CreateScopedMigrationRequest) {
    MigrateInfo migrateInfo = makeMigrateInfo();

    {
        ScopedMigrationRequest scopedMigrationRequest = assertGet(
            ScopedMigrationRequest::writeMigration(operationContext(), migrateInfo, false));

            

Reported by Cppcheck.

src/mongo/db/s/balancer/type_migration_test.cpp
1 issues
syntax error
Error

Line: 50

              const ShardId kToShard("shard0001");
const bool kWaitForDelete{true};

TEST(MigrationTypeTest, ConvertFromMigrationInfo) {
    const auto collEpoch = OID::gen();
    const auto collTimestamp = boost::none;
    const ChunkVersion version(1, 2, collEpoch, collTimestamp);

    BSONObjBuilder chunkBuilder;

            

Reported by Cppcheck.

src/mongo/db/s/chunk_split_state_driver_test.cpp
1 issues
syntax error
Error

Line: 73

                  }
};

TEST(ChunkSplitStateDriverTest, InitiateSplitLeavesBytesWrittenUnchanged) {
    auto writesTracker = std::make_shared<ChunkWritesTracker>();
    uint64_t bytesInTrackerBeforeSplit{4};
    writesTracker->addBytesWritten(bytesInTrackerBeforeSplit);

    auto splitDriver = ChunkSplitStateDriver::tryInitiateSplit(writesTracker);

            

Reported by Cppcheck.

src/mongo/db/s/collection_metadata_filtering_test.cpp
1 issues
syntax error
Error

Line: 138

              };

// Verifies that right set of documents is visible
TEST_F(CollectionMetadataFilteringTest, FilterDocumentsInTheFuture) {
    prepareTestData();

    const auto testFilterFn = [](const ScopedCollectionFilter& collectionFilter) {
        ASSERT_TRUE(collectionFilter.keyBelongsToMe(BSON("_id" << -500)));
        ASSERT_TRUE(collectionFilter.keyBelongsToMe(BSON("_id" << 50)));

            

Reported by Cppcheck.

src/mongo/db/s/collection_metadata_test.cpp
1 issues
syntax error
Error

Line: 142

                  }
};

TEST_F(NoChunkFixture, KeyBelongsToMe) {
    ASSERT(!makeCollectionMetadata().keyBelongsToMe(BSON("a" << MINKEY)));
    ASSERT(!makeCollectionMetadata().keyBelongsToMe(BSON("a" << 10)));
    ASSERT(!makeCollectionMetadata().keyBelongsToMe(BSON("a" << MINKEY)));

    ASSERT(!makeCollectionMetadata().keyBelongsToMe(BSONObj()));

            

Reported by Cppcheck.

src/mongo/db/s/collection_sharding_runtime_test.cpp
1 issues
syntax error
Error

Line: 94

                  }
};

TEST_F(CollectionShardingRuntimeTest,
       GetCollectionDescriptionThrowsStaleConfigBeforeSetFilteringMetadataIsCalledAndNoOSSSet) {
    OperationContext* opCtx = operationContext();
    CollectionShardingRuntime csr(getServiceContext(), kTestNss, executor());
    ASSERT_FALSE(csr.getCollectionDescription(opCtx).isSharded());
    makeShardedMetadata(opCtx);

            

Reported by Cppcheck.

src/mongo/db/s/config/initial_split_policy_test.cpp
1 issues
syntax error
Error

Line: 88

                  ASSERT_EQUALS(expectNumChunkPerShard, policy.getNumContiguousChunksPerShard());
}

TEST(CalculateHashedSplitPointsTest, HashedPrefixMoreChunksThanShardsWithEqualDistribution) {
    auto shardKeyPattern = ShardKeyPattern(BSON("x"
                                                << "hashed"
                                                << "y" << 1));
    const std::vector<BSONObj> expectedSplitPoints = {
        BSON("x" << -4611686018427387902LL << "y" << MINKEY),

            

Reported by Cppcheck.