The following issues were found

src/mongo/s/write_ops/batch_write_exec_test.cpp
1 issues
syntax error
Error

Line: 294

              // Tests for the BatchWriteExec
//

TEST_F(BatchWriteExecTest, SingleOpUnordered) {
    BatchedCommandRequest request([&] {
        write_ops::InsertCommandRequest insertOp(nss);
        insertOp.setWriteCommandRequestBase([] {
            write_ops::WriteCommandRequestBase writeCommandBase;
            writeCommandBase.setOrdered(false);

            

Reported by Cppcheck.

src/mongo/s/write_ops/batch_write_op_test.cpp
1 issues
syntax error
Error

Line: 122

              
using BatchWriteOpTest = WriteOpTestFixture;

TEST_F(BatchWriteOpTest, SingleOp) {
    NamespaceString nss("foo.bar");
    ShardEndpoint endpoint(ShardId("shard"), ChunkVersion::IGNORED(), boost::none);

    auto targeter = initTargeterFullRange(nss, endpoint);


            

Reported by Cppcheck.

src/mongo/s/write_ops/batched_command_request_test.cpp
1 issues
syntax error
Error

Line: 59

                  }
}

TEST(BatchedCommandRequest, InsertWithShardVersion) {
    BSONArray insertArray = BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1));

    const OID epoch = OID::gen();

    BSONObj origInsertRequestObj = BSON("insert"

            

Reported by Cppcheck.

src/mongo/s/write_ops/batched_command_response_test.cpp
1 issues
syntax error
Error

Line: 81

                      << "\noriginal: " << origResponseObj;
}

TEST(BatchedCommandResponse, TooManySmallErrors) {
    BatchedCommandResponse response;

    const auto bigstr = std::string(1024, 'x');

    for (int i = 0; i < 100'000; i++) {

            

Reported by Cppcheck.

src/mongo/s/write_ops/write_op_test.cpp
1 issues
syntax error
Error

Line: 78

              };

// Test of basic error-setting on write op
TEST_F(WriteOpTest, BasicError) {
    BatchedCommandRequest request([&] {
        write_ops::InsertCommandRequest insertOp(kNss);
        insertOp.setDocuments({BSON("x" << 1)});
        return insertOp;
    }());

            

Reported by Cppcheck.

src/mongo/scripting/bson_template_evaluator_test.cpp
1 issues
syntax error
Error

Line: 69

                                t->evaluate(BSON("randField" << outerRandObj), builder4));
}

TEST(BSONTemplateEvaluatorTest, RAND_INT) {
    BsonTemplateEvaluator t(1234567);
    int randValue1, randValue2;

    common_rand_tests("#RAND_INT", &t);


            

Reported by Cppcheck.

src/mongo/scripting/deadline_monitor_test.cpp
1 issues
syntax error
Error

Line: 86

              };

// single task expires before stopping the deadline
TEST(DeadlineMonitor, ExpireThenRemove) {
    DeadlineMonitor<Task> dm;
    TaskGroup group;
    Task task(&group);
    dm.startDeadline(&task, 10);
    group.waitForKillCount(1);

            

Reported by Cppcheck.

src/mongo/scripting/mozjs/jsstringwrapper.cpp
1 issues
strncpy - Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned]
Security

Line: 48 Column: 5 CWE codes: 120

              JSStringWrapper::JSStringWrapper(std::int32_t value) : _isSet(true) {
    auto formatted = fmt::format_int(value);
    _length = formatted.size();
    strncpy(_buf, formatted.c_str(), sizeof(_buf) - 1);
    _buf[sizeof(_buf) - 1] = '\0';
}

JSStringWrapper::JSStringWrapper(JSContext* cx, JSString* str) : _isSet(true) {
    if (!str)

            

Reported by FlawFinder.

src/mongo/scripting/mozjs/jsstringwrapper.h
1 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 64 Column: 5 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              private:
    std::unique_ptr<char[]> _str;
    size_t _length = 0;
    char _buf[64];
    bool _isSet = false;
};

}  // namespace mozjs
}  // namespace mongo

            

Reported by FlawFinder.

src/mongo/scripting/utils.cpp
1 issues
strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 48 Column: 43 CWE codes: 126

                  md5digest d;
    md5_state_t st;
    md5_init(&st);
    md5_append(&st, (const md5_byte_t*)s, strlen(s));
    md5_finish(&st, d);

    return BSON("" << digestToString(d));
}


            

Reported by FlawFinder.