The following issues were found

src/mongo/db/fts/fts_basic_tokenizer_test.cpp
1 issues
syntax error
Error

Line: 54

              
// Ensure punctuation is filtered out of the indexed document
// and the 's is not separated
TEST(FtsBasicTokenizer, English) {
    std::vector<std::string> terms = tokenizeString("Do you see Mark's dog running?", "english");

    ASSERT_EQUALS(6U, terms.size());
    ASSERT_EQUALS("do", terms[0]);
    ASSERT_EQUALS("you", terms[1]);

            

Reported by Cppcheck.

src/mongo/db/fts/fts_element_iterator_test.cpp
1 issues
syntax error
Error

Line: 42

              using std::string;
using unittest::assertGet;

TEST(FTSElementIterator, Test1) {
    BSONObj obj = fromjson(
        "{ b : \"walking\","
        "  c : { e: \"walked\" },"
        "  d : \"walker\""
        "  }");

            

Reported by Cppcheck.

src/mongo/db/fts/fts_index_format.cpp
1 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 199 Column: 17 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

                      } else {
            union {
                uint64_t hash[2];
                char data[16];
            } t;
            uint32_t seed = 0;
            MurmurHash3_x64_128(term.data(), term.size(), seed, t.hash);
            string keySuffix = hexblob::encodeLower(t.data, sizeof(t.data));
            invariant(termKeySuffixLengthV2 == keySuffix.size());

            

Reported by FlawFinder.

src/mongo/db/fts/fts_index_format_test.cpp
1 issues
syntax error
Error

Line: 50

              using std::string;
using unittest::assertGet;

TEST(FTSIndexFormat, Simple1) {
    FTSSpec spec(assertGet(FTSSpec::fixSpec(BSON("key" << BSON("data"
                                                               << "text")))));
    SharedBufferFragmentBuilder allocator(BufBuilder::kDefaultInitSizeBytes);
    KeyStringSet keys;
    FTSIndexFormat::getKeys(allocator,

            

Reported by Cppcheck.

src/mongo/db/fts/fts_language_test.cpp
1 issues
syntax error
Error

Line: 55

                  ASSERT_THROWS(FTSLanguage::make("spanglish", kVer), LanguageMakeException);
}

TEST(FTSLanguageV2, Make) {
    static constexpr auto kVer = TEXT_INDEX_VERSION_2;
    ASSERT_EQUALS(FTSLanguage::make("spanish", kVer).str(), "spanish");
    ASSERT_EQUALS(FTSLanguage::make("es", kVer).str(), "spanish");
    ASSERT_EQUALS(FTSLanguage::make("SPANISH", kVer).str(), "spanish");
    ASSERT_EQUALS(FTSLanguage::make("ES", kVer).str(), "spanish");

            

Reported by Cppcheck.

src/mongo/db/fts/fts_matcher_test.cpp
1 issues
syntax error
Error

Line: 40

              
using unittest::assertGet;

TEST(FTSMatcher, NegWild1) {
    FTSQueryImpl q;
    q.setQuery("foo -bar");
    q.setLanguage("english");
    q.setCaseSensitive(false);
    q.setDiacriticSensitive(false);

            

Reported by Cppcheck.

src/mongo/db/fts/fts_query_impl_test.cpp
1 issues
syntax error
Error

Line: 56

                  ASSERT_TRUE(q.getTermsForBounds() == q.getPositiveTerms());
}

TEST(FTSQueryImpl, ParsePunctuation) {
    FTSQueryImpl q;
    q.setQuery("hello.world");
    q.setLanguage("english");
    q.setCaseSensitive(false);
    q.setDiacriticSensitive(false);

            

Reported by Cppcheck.

src/mongo/db/fts/fts_query_noop_test.cpp
1 issues
syntax error
Error

Line: 43

                  ASSERT_OK(q.parse(TEXT_INDEX_VERSION_INVALID));
}

TEST(FTSQueryNoop, Clone) {
    FTSQueryNoop q;
    q.setQuery("foo");
    q.setLanguage("bar");
    q.setCaseSensitive(true);
    q.setDiacriticSensitive(true);

            

Reported by Cppcheck.

src/mongo/db/fts/fts_spec_legacy.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: 57 Column: 13 CWE codes: 126

                  BSONElement e = userDoc[_languageOverrideField];
    if (e.type() == String) {
        const char* x = e.valuestrsafe();
        if (strlen(x) > 0) {
            // make() w/ TEXT_INDEX_VERSION_1 guaranteed to not fail.
            return FTSLanguage::make(x, TEXT_INDEX_VERSION_1);
        }
    }
    return *_defaultLanguage;

            

Reported by FlawFinder.

src/mongo/db/fts/fts_spec_test.cpp
1 issues
syntax error
Error

Line: 70

                  ASSERT_NOT_OK(FTSSpec::fixSpec(user));
}

TEST(FTSSpec, FixNormalKey1) {
    assertFixSuccess("{key: {a: 'text'}}");
    assertFixSuccess("{key: {a: 'text', b: 'text'}}");
    assertFixSuccess("{key: {a: 'text', b: 'text', c: 'text'}}");

    assertFixFailure("{key: {_fts: 'text'}}");  // not allowed to index reserved field

            

Reported by Cppcheck.