diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2019-05-10 10:58:40 -0400 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2019-05-10 12:58:46 -0400 |
commit | 5ec2e2508bec5cc64ea36f01f502c756c3e84597 (patch) | |
tree | 7c8be10d8f9814d1c53713fa10aa346068e46948 /src | |
parent | 97dd5eae1899073c100bac86f9971478bd76bb7a (diff) | |
download | mongo-5ec2e2508bec5cc64ea36f01f502c756c3e84597.tar.gz |
SERVER-41082: Avoid divide by zero in flow control.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/storage/flow_control.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/mongo/db/storage/flow_control.cpp b/src/mongo/db/storage/flow_control.cpp index 6c7d1bd7376..18642c49e10 100644 --- a/src/mongo/db/storage/flow_control.cpp +++ b/src/mongo/db/storage/flow_control.cpp @@ -54,6 +54,11 @@ const auto getFlowControl = ServiceContext::declareDecoration<std::unique_ptr<Fl const int kMaxTickets = 1000 * 1000 * 1000; int multiplyWithOverflowCheck(double term1, double term2, int maxValue) { + if (term1 == 0.0 || term2 == 0.0) { + // Early return to avoid any divide by zero errors. + return 0; + } + if (static_cast<double>(std::numeric_limits<int>::max()) / term2 < term1) { // Multiplying term1 and term2 would overflow, return maxValue. return maxValue; |