The following issues were found
src/mongo/db/update/document_diff_calculator_test.cpp
1 issues
Line: 58
assertDiffEmpty(fromjson("{'0': [[{'0': [[{'0': [[]]} ]]}]]}"));
}
TEST(DocumentDiffCalculatorTest, LargeDelta) {
ASSERT_FALSE(doc_diff::computeDiff(
fromjson("{a: 1, b: 2, c: 3}"), fromjson("{A: 1, B: 2, C: 3}"), 0, nullptr));
// Inserting field at the beginning produces a large delta.
ASSERT_FALSE(doc_diff::computeDiff(
Reported by Cppcheck.
src/mongo/db/update/document_diff_serialization.cpp
1 issues
Line: 283
Column: 9
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
// +1 for leading char. +1 to round up from digits10.
static constexpr size_t fieldNameSize = std::numeric_limits<std::uint64_t>::digits10 + 2;
char fieldNameStorage[fieldNameSize];
auto formatFieldName = [&](char pre, size_t idx) {
const char* fieldNameStorageEnd =
fmt::format_to(fieldNameStorage, FMT_STRING("{}{}"), pre, idx);
return StringData(static_cast<const char*>(fieldNameStorage), fieldNameStorageEnd);
Reported by FlawFinder.
src/mongo/db/update/document_diff_serialization_test.cpp
1 issues
Line: 53
return storage.firstElement();
}
TEST(DiffSerializationTest, DeleteSimple) {
diff_tree::DocumentSubDiffNode diffNode;
StringData fieldName1 = "f1";
StringData fieldName2 = "f2";
StringData fieldName3 = "f3";
diffNode.addDelete(fieldName1);
Reported by Cppcheck.
src/mongo/db/update/document_diff_test.cpp
1 issues
Line: 179
}
}
TEST(DocumentDiffTest, PredefinedDocumentsTest) {
TestOptions options;
options.documents = getDocumentsRepo();
runTest(&options);
}
Reported by Cppcheck.
src/mongo/db/update/field_checker_test.cpp
1 issues
Line: 45
using mongo::fieldchecker::isPositional;
using mongo::fieldchecker::isUpdatable;
TEST(IsUpdatable, Basics) {
FieldRef fieldRef("x");
ASSERT_OK(isUpdatable(fieldRef));
}
TEST(IsUpdatable, DottedFields) {
Reported by Cppcheck.
src/mongo/db/update/modifier_table_test.cpp
1 issues
Line: 42
using std::unique_ptr;
TEST(getType, Normal) {
ASSERT_EQUALS(getType("$set"), MOD_SET);
ASSERT_EQUALS(getType("$AModThatDoesn'tExist"), MOD_UNKNOWN);
ASSERT_EQUALS(getType("NotAModExpression"), MOD_UNKNOWN);
}
Reported by Cppcheck.
src/mongo/db/update/object_replace_executor.cpp
1 issues
Line: 64
Column: 58
CWE codes:
120
20
auto timestampView = DataView(const_cast<char*>(elem.value()));
// We don't need to do an endian-safe read here, because 0 is 0 either way.
unsigned long long timestamp = timestampView.read<unsigned long long>();
if (timestamp == 0) {
ServiceContext* service = getGlobalServiceContext();
auto ts = VectorClockMutable::get(service)->tickClusterTime(1).asTimestamp();
timestampView.write(tagLittleEndian(ts.asULL()));
}
Reported by FlawFinder.
src/mongo/db/update/object_replace_executor_test.cpp
1 issues
Line: 48
using mongo::mutablebson::countChildren;
using mongo::mutablebson::Element;
TEST_F(ObjectReplaceExecutorTest, Noop) {
auto obj = fromjson("{a: 1, b: 2}");
ObjectReplaceExecutor node(obj);
mutablebson::Document doc(fromjson("{a: 1, b: 2}"));
auto result = node.applyUpdate(getApplyParams(doc.root()));
Reported by Cppcheck.
src/mongo/db/update/path_support_test.cpp
1 issues
Line: 90
FieldRef _field;
};
TEST_F(EmptyDoc, EmptyPath) {
setField("");
FieldIndex idxFound;
Element elemFound = root();
Status status = findLongestPrefix(field(), root(), &idxFound, &elemFound);
Reported by Cppcheck.
src/mongo/db/update/pipeline_executor_test.cpp
1 issues
Line: 89
}
};
TEST_F(PipelineExecutorTest, Noop) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
std::vector<BSONObj> pipeline{fromjson("{$addFields: {a: 1, b: 2}}")};
PipelineExecutor exec(expCtx, pipeline);
Reported by Cppcheck.