The following issues were found

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

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

                          "sizeAfter"_attr = sizeAfter,
            "size"_attr = size);
    }
    memcpy(storage.get(), objdata(), size);
    return BSONObj(std::move(storage));
}

BSONObj BSONObj::getOwned() const {
    if (isOwned())

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

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

                  }

    if (ptr) {
        std::memcpy(ptr, bson.objdata(), bson.objsize());
    }

    if (advanced) {
        *advanced = bson.objsize();
    }

            

Reported by FlawFinder.

buildscripts/idl/tests/test_parser.py
2 issues
Attempted relative import beyond top-level package
Error

Line: 44 Column: 5

                  from context import idl
    import testcase
else:
    from .context import idl
    from . import testcase


class TestParser(testcase.IDLTestcase):
    # pylint: disable=too-many-public-methods

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 45 Column: 5

                  import testcase
else:
    from .context import idl
    from . import testcase


class TestParser(testcase.IDLTestcase):
    # pylint: disable=too-many-public-methods
    """Test the IDL parser only."""

            

Reported by Pylint.

src/mongo/base/data_type_terminated.cpp
2 issues
read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 46 Column: 57 CWE codes: 120 20

              }

Status TerminatedHelper::makeLoadShortReadStatus(char c,
                                                 size_t read,
                                                 size_t length,
                                                 std::ptrdiff_t debug_offset) {
    str::stream ss;
    ss << "only read (" << read << ") bytes. (" << length << ") bytes to terminal char ("
       << str::escape(StringData(&c, 1)) << ") at offset: " << debug_offset;

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 50 Column: 28 CWE codes: 120 20

                                                               size_t length,
                                                 std::ptrdiff_t debug_offset) {
    str::stream ss;
    ss << "only read (" << read << ") bytes. (" << length << ") bytes to terminal char ("
       << str::escape(StringData(&c, 1)) << ") at offset: " << debug_offset;

    return Status(ErrorCodes::Overflow, ss);
}


            

Reported by FlawFinder.

src/third_party/abseil-cpp-master/abseil-cpp/absl/strings/cord_ring_reader_test.cc
2 issues
syntax error
Error

Line: 58

                        "+-=",        "[]\\{}|;':", ",/<>?",      "."};
}

TEST(CordRingReaderTest, DefaultInstance) {
  CordRepRingReader reader;
  EXPECT_FALSE(static_cast<bool>(reader));
  EXPECT_THAT(reader.ring(), Eq(nullptr));
#ifndef NDEBUG
  EXPECT_DEATH_IF_SUPPORTED(reader.length(), ".*");

            

Reported by Cppcheck.

memcpy - Does not check for buffer overflows when copying to destination
Security

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

              // Creates a flat for testing
CordRep* MakeFlat(absl::string_view s) {
  CordRepFlat* flat = CordRepFlat::New(s.length());
  memcpy(flat->Data(), s.data(), s.length());
  flat->length = s.length();
  return flat;
}

CordRepRing* FromFlats(Span<absl::string_view const> flats) {

            

Reported by FlawFinder.

src/mongo/util/stacktrace_test.cpp
2 issues
syntax error
Error

Line: 155

              }

// Break down a printStackTrace output for a contrived call tree and sanity-check it.
TEST(StackTrace, PosixFormat) {
    if (kIsWindows) {
        return;
    }

    std::string trace;

            

Reported by Cppcheck.

printf - If format strings can be influenced by an attacker, they can be exploited
Security

Line: 334 Column: 43 CWE codes: 134
Suggestion: Use a constant for the format specification

                      {
            // printf's file tricky (surprises under ASAN, Mac, ...),
            // but we should at least get a symbol name containing "printf" out of it.
            reinterpret_cast<void*>(&std::printf),
            {},
            "printf",
        },
    };


            

Reported by FlawFinder.

src/third_party/boost/boost/archive/iterators/mb_from_wchar.hpp
2 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 114 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

                  boost::archive::detail::utf8_codecvt_facet m_codecvt_facet;
    std::mbstate_t m_mbs;
    // buffer to handle pending characters
    char m_buffer[9 /* MB_CUR_MAX */];
    std::size_t m_bend;
    std::size_t m_bnext;
    bool m_full;

public:

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 75 Column: 10 CWE codes: 126
Suggestion: This function is often discouraged by most C++ coding standards in favor of its safer alternatives provided since C++14. Consider using a form of this function that checks the second iterator before potentially overflowing it

                      return (const_cast<this_t *>(this))->dereference_impl();
    }
    // test for iterator equality
    bool equal(const mb_from_wchar<Base> & rhs) const {
        // once the value is filled, the base_reference has been incremented
        // so don't permit comparison anymore.
        return
            0 == m_bend
            && 0 == m_bnext

            

Reported by FlawFinder.

src/third_party/asio-master/asio/include/asio/detail/win_iocp_socket_accept_op.hpp
2 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 155 Column: 12 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

                Socket& peer_;
  Protocol protocol_;
  typename Protocol::endpoint* peer_endpoint_;
  unsigned char output_buffer_[(sizeof(sockaddr_storage_type) + 16) * 2];
  bool enable_connection_aborted_;
  Handler handler_;
};

#if defined(ASIO_HAS_MOVE)

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 283 Column: 12 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

                typename Protocol::socket peer_;
  Protocol protocol_;
  typename Protocol::endpoint* peer_endpoint_;
  unsigned char output_buffer_[(sizeof(sockaddr_storage_type) + 16) * 2];
  bool enable_connection_aborted_;
  Handler handler_;
};

#endif // defined(ASIO_HAS_MOVE)

            

Reported by FlawFinder.

src/third_party/abseil-cpp-master/abseil-cpp/absl/strings/escaping_test.cc
2 issues
syntax error
Error

Line: 37

                std::string unescaped;
};

TEST(CEscape, EscapeAndUnescape) {
  const std::string inputs[] = {
      std::string("foo\nxx\r\b\0023"),
      std::string(""),
      std::string("abc"),
      std::string("\1chad_rules"),

            

Reported by Cppcheck.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 90 Column: 7 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

                // unescaped successfully.
  for (int char0 = 0; char0 < 256; char0++) {
    for (int char1 = 0; char1 < 256; char1++) {
      char chars[2];
      chars[0] = char0;
      chars[1] = char1;
      std::string s(chars, 2);
      std::string escaped = absl::CHexEscape(s);
      std::string unescaped;

            

Reported by FlawFinder.

src/mongo/db/free_mon/free_mon_mongod.cpp
2 issues
read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 113 Column: 35 CWE codes: 120 20

                          auto blobSize = blob.size();
            auto blobData = blob.release();
            ConstDataRange cdr(blobData.get(), blobSize);
            BSONObj respObj = cdr.read<Validated<BSONObj>>();

            auto resp =
                FreeMonRegistrationResponse::parse(IDLParserErrorContext("response"), respObj);

            return resp;

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 136 Column: 35 CWE codes: 120 20

                          auto blobData = blob.release();
            ConstDataRange cdr(blobData.get(), blobSize);

            BSONObj respObj = cdr.read<Validated<BSONObj>>();

            auto resp = FreeMonMetricsResponse::parse(IDLParserErrorContext("response"), respObj);

            return resp;
        });

            

Reported by FlawFinder.

src/mongo/db/index/wildcard_key_generator_test.cpp
2 issues
syntax error
Error

Line: 97

              // Full-document tests with no projection.
struct WildcardKeyGeneratorFullDocumentTest : public WildcardKeyGeneratorTest {};

TEST_F(WildcardKeyGeneratorFullDocumentTest, ExtractTopLevelKey) {
    WildcardKeyGenerator keyGen{fromjson("{'$**': 1}"),
                                {},
                                nullptr,
                                KeyString::Version::kLatestVersion,
                                Ordering::make(BSONObj()),

            

Reported by Cppcheck.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 78 Column: 15 CWE codes: 126
Suggestion: This function is often discouraged by most C++ coding standards in favor of its safer alternatives provided since C++14. Consider using a form of this function that checks the second iterator before potentially overflowing it

                      return false;
    }

    if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) {
        LOGV2(20696,
              "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
              "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
              "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
        return false;

            

Reported by FlawFinder.