summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorMartin Neupauer <martin.neupauer@mongodb.com>2017-08-17 13:54:14 -0400
committerMartin Neupauer <martin.neupauer@mongodb.com>2017-08-18 12:09:32 -0400
commit5bdeccdef411b3c8e19c19b2e5190119889eba61 (patch)
treeb9618f98f39e6c142fd3c3834f8cb9122af19a88 /src/mongo/bson
parent1ee537356bbd98a6c037e40b7d4f04283a11741d (diff)
downloadmongo-5bdeccdef411b3c8e19c19b2e5190119889eba61.tar.gz
SERVER-30720 Integer overflow in SharedBuffer::grow_reallocate
Move the length check before the while loop.
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/util/builder.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index 9d4ad89d1a0..b7a4525a17b 100644
--- a/src/mongo/bson/util/builder.h
+++ b/src/mongo/bson/util/builder.h
@@ -340,15 +340,16 @@ private:
}
/* "slow" portion of 'grow()' */
void NOINLINE_DECL grow_reallocate(int minSize) {
+ if (minSize > BufferMaxSize) {
+ std::stringstream ss;
+ ss << "BufBuilder attempted to grow() to " << minSize << " bytes, past the 64MB limit.";
+ msgasserted(13548, ss.str().c_str());
+ }
+
int a = 64;
while (a < minSize)
a = a * 2;
- if (a > BufferMaxSize) {
- std::stringstream ss;
- ss << "BufBuilder attempted to grow() to " << a << " bytes, past the 64MB limit.";
- msgasserted(13548, ss.str().c_str());
- }
_buf.realloc(a);
size = a;
}