The following issues were found
src/mongo/rpc/metadata/egress_metadata_hook_list_test.cpp
1 issues
Line: 93
Status _toRet;
};
TEST(EgressMetadataHookListTest, EmptyHookShouldNotFail) {
EgressMetadataHookList hookList;
ASSERT_OK(hookList.writeRequestMetadata(nullptr, nullptr));
BSONObj emptyObj;
ASSERT_OK(hookList.readReplyMetadata(nullptr, "", emptyObj));
Reported by Cppcheck.
src/mongo/rpc/metadata/oplog_query_metadata_test.cpp
1 issues
Line: 42
using repl::OpTime;
TEST(ReplResponseMetadataTest, OplogQueryMetadataRoundtrip) {
OpTime opTime1(Timestamp(1234, 100), 5);
Date_t committedWall = Date_t() + Seconds(opTime1.getSecs());
OpTime opTime2(Timestamp(7777, 101), 6);
OplogQueryMetadata metadata({opTime1, committedWall}, opTime2, 6, 12, -1);
Reported by Cppcheck.
src/mongo/rpc/metadata/repl_set_metadata_test.cpp
1 issues
Line: 49
static const ReplSetMetadata metadata(
3, {opTime, committedWallTime}, opTime2, 6, 0, OID("abcdefabcdefabcdefabcdef"), -1, false);
TEST(ReplResponseMetadataTest, ReplicaSetIdNotSet) {
ASSERT_FALSE(ReplSetMetadata(3, OpTimeAndWallTime(), OpTime(), 6, 0, OID(), -1, false)
.hasReplicaSetId());
}
TEST(ReplResponseMetadataTest, Roundtrip) {
Reported by Cppcheck.
src/mongo/rpc/metadata/security_token_metadata_test.cpp
1 issues
Line: 50
class SecurityTokenMetadataTest : public ServiceContextTest {};
TEST_F(SecurityTokenMetadataTest, SecurityTokenNotAccepted) {
const auto kPingBody = BSON(kPingFieldName << 1);
const auto kTokenBody = BSON(kTenantFieldName << OID::gen());
auth::gAcceptOpMsgSecurityToken = false;
auto msgBytes = OpMsgBytes{0, kBodySection, kPingBody, kSecurityTokenSection, kTokenBody};
Reported by Cppcheck.
src/mongo/rpc/metadata/tracking_metadata_test.cpp
1 issues
Line: 53
const auto kOperName = "testCmd";
const auto kParentOperId = "541b1a00e8a23afa832b2016";
TEST(TrackingMetadata, ReadFromMetadata) {
{
auto metadata =
checkParse(BSON("tracking_info" << BSON("operId" << kOperId << "operName" << kOperName
<< "parentOperId" << kParentOperId)));
ASSERT_EQ(*metadata.getOperId(), kOperId);
Reported by Cppcheck.
src/mongo/rpc/metadata_test.cpp
1 issues
Line: 68
ASSERT_BSONOBJ_EQ(sorted(upconvertedCommand), sorted(converted.body));
}
TEST(Metadata, UpconvertValidMetadata) {
// Wrapped in $query, with readPref and slaveOk bit set.
checkUpconvert(BSON("$query" << BSON("ping" << 1) << //
"$readPreference"
<< BSON("mode"
<< "secondary")),
Reported by Cppcheck.
src/mongo/rpc/op_msg_integration_test.cpp
1 issues
Line: 88
return batch.empty() ? "" : batch[0].getStringField("desc");
}
TEST(OpMsg, UnknownRequiredFlagClosesConnection) {
auto conn = getIntegrationTestConnection();
auto request = OpMsgRequest::fromDBAndBody("admin", BSON("ping" << 1)).serialize();
OpMsg::setFlag(&request, 1u << 15); // This should be the last required flag to be assigned.
Reported by Cppcheck.
src/mongo/rpc/op_msg_test.cpp
1 issues
Line: 59
constexpr uint32_t kNoFlags = 0;
constexpr uint32_t kHaveChecksum = OpMsg::kChecksumPresent;
TEST_F(OpMsgParser, SucceedsWithJustBody) {
auto msg =
OpMsgBytes{
kNoFlags, //
kBodySection,
fromjson("{ping: 1}"),
Reported by Cppcheck.
src/mongo/rpc/op_msg_test.h
1 issues
Line: 126
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
const auto orig = Message(buffer.release());
// Copy the message to an exact-sized allocation so ASAN can detect out-of-bounds accesses.
auto copy = SharedBuffer::allocate(orig.size());
memcpy(copy.get(), orig.buf(), orig.size());
return Message(std::move(copy));
}
OpMsg parse() {
return OpMsg::parseOwned(done());
Reported by FlawFinder.
src/mongo/rpc/protocol_fuzzer.cpp
1 issues
Line: 67
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
serverGlobalParams.objcheck = true;
auto sb = SharedBuffer::allocate(fuzzedData.length());
memcpy(sb.get(), fuzzedData.data(), fuzzedData.length());
Message msg(std::move(sb));
if (static_cast<size_t>(msg.size()) != fuzzedData.length()) {
return;
}
Reported by FlawFinder.