The following issues were found
src/mongo/util/future_test_utils.h
1 issues
Line: 98
Column: 40
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
inline void sleepIfShould() {
#if !__has_feature(thread_sanitizer)
// TSAN and rr work better without this sleep, but it is useful for testing correctness.
static const bool runningUnderRR = getenv("RUNNING_UNDER_RR") != nullptr;
if (!runningUnderRR)
sleepmillis(100); // Try to wait until after the Future has been handled.
#endif
}
Reported by FlawFinder.
src/mongo/util/future_util_test.cpp
1 issues
Line: 89
using AsyncTryUntilTest = FutureUtilTest;
TEST_F(AsyncTryUntilTest, LoopExecutesOnceWithAlwaysTrueCondition) {
auto i = 0;
auto resultFut = AsyncTry([&] { ++i; })
.until([](Status s) { return true; })
.on(executor(), CancellationToken::uncancelable());
resultFut.wait();
Reported by Cppcheck.
src/mongo/util/hash_table_bm.cpp
1 issues
Line: 96
Column: 9
CWE codes:
120
Suggestion:
Use sprintf_s, snprintf, or vsnprintf
_mem = std::make_unique<char[]>(kMaxContainerSize * 10);
_current = _mem.get();
}
sprintf(_current, "%u", i);
StringData sd(_current);
_current += sd.size();
return sd;
}
Reported by FlawFinder.
src/mongo/util/heap_profiler.cpp
1 issues
Line: 341
Column: 22
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
bool operator==(const Stack& that) {
return this->numFrames == that.numFrames &&
std::equal(frames.begin(), frames.begin() + numFrames, that.frames.begin());
}
Hash hash() {
Hash hash;
MONGO_STATIC_ASSERT_MSG(sizeof(frames) == sizeof(FrameInfo) * kMaxFramesPerStack,
Reported by FlawFinder.
src/mongo/util/hierarchical_acquisition_test.cpp
1 issues
Line: 89
Set _set;
};
TEST_F(HierarchicalAcquisitionTest, AcquireRelease) {
// This test performs the simplest idempotent set of successful operations on a single level L1:
// - add(L1) suceeds because nothing is set
// - remove(L1) suceeds because only L1 is set
for (auto i = Level::kMinIndex; i <= Level::kMaxIndex; ++i) {
Reported by Cppcheck.
src/mongo/util/icu_test.cpp
1 issues
Line: 44
bool success;
};
TEST(ICUTest, icuSaslPrep) {
const testCases tests[] = {
// U+0065 LATIN SMALL LETTER E + U+0301 COMBINING ACUTE ACCENT
// U+00E9 LATIN SMALL LETTER E WITH ACUTE
{"\x65\xCC\x81", "\xC3\xA9", true},
Reported by Cppcheck.
src/mongo/util/integer_histogram_test.cpp
1 issues
Line: 65
ASSERT_EQUALS(buckets["mean"].Double(), static_cast<double>(sum) / numInserts);
}
TEST(IntegerHistogram, EnsureCountsIncrementedInSmallestBucket) {
std::array<int64_t, 3> lowerBounds{5, 8, 12};
IntegerHistogram<3> hist("testKey2", lowerBounds);
int64_t sum = 0;
int64_t numInserts = 5;
for (int64_t i = 0; i < numInserts; i++) {
Reported by Cppcheck.
src/mongo/util/invalidating_lru_cache_test.cpp
1 issues
Line: 60
using TestValueCacheCausallyConsistent = InvalidatingLRUCache<int, TestValue, Timestamp>;
using TestValueHandleCausallyConsistent = TestValueCacheCausallyConsistent::ValueHandle;
TEST(InvalidatingLRUCacheTest, StandaloneValueHandle) {
TestValueHandle standaloneHandle({"Standalone value"});
ASSERT(standaloneHandle.isValid());
ASSERT_EQ("Standalone value", standaloneHandle->value);
}
Reported by Cppcheck.
src/mongo/util/itoa.h
1 issues
Line: 62
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:
StringData _str;
char _buf[kBufSize];
};
} // namespace mongo
Reported by FlawFinder.
src/mongo/util/latch_analyzer_test.cpp
1 issues
Line: 45
class LatchAnalyzerTest : public ServiceContextTest {};
DEATH_TEST_REGEX_F(LatchAnalyzerTest, AddInvalidWasAbsent, "Fatal assertion.*5106800") {
Mutex lowerLevel = MONGO_MAKE_LATCH(Level(1), "AddInvalidWasAbsent::lowerLevel");
Mutex higherLevel = MONGO_MAKE_LATCH(Level(2), "AddInvalidWasAbsent::higherLevel");
lowerLevel.lock();
Reported by Cppcheck.