summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2019-06-03 11:17:25 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2019-06-03 11:17:25 -0400
commit28000675e7cf1b6ab55a0aaa0fcb07a7f3c49512 (patch)
treed047a2fcf79285b4d2408d63f5f1704e9085e7f4 /src/mongo/idl
parent16a18a5370f276ca5ec91bfc13b2738390b319e8 (diff)
downloadmongo-28000675e7cf1b6ab55a0aaa0fcb07a7f3c49512.tar.gz
SERVER-41024 safeInt64 IDL types are not safe for all numerical inputs, results in UB
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/basic_types.idl12
-rw-r--r--src/mongo/idl/idl_test.cpp24
-rw-r--r--src/mongo/idl/unittest.idl12
3 files changed, 19 insertions, 29 deletions
diff --git a/src/mongo/idl/basic_types.idl b/src/mongo/idl/basic_types.idl
index e91ce1ec2b1..084ca20fe42 100644
--- a/src/mongo/idl/basic_types.idl
+++ b/src/mongo/idl/basic_types.idl
@@ -46,16 +46,6 @@ types:
cpp_type: "std::int32_t"
deserializer: "mongo::BSONElement::_numberInt"
- safeInt32:
- bson_serialization_type:
- - long
- - int
- - decimal
- - double
- description: "Accepts any numerical type within int32 range"
- cpp_type: std::int32_t
- deserializer: "mongo::BSONElement::numberInt"
-
safeInt64:
bson_serialization_type:
- long
@@ -64,7 +54,7 @@ types:
- double
description: "Accepts any numerical type within int64 range"
cpp_type: std::int64_t
- deserializer: "mongo::BSONElement::numberLong"
+ deserializer: "mongo::BSONElement::safeNumberLong"
long:
bson_serialization_type: long
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp
index 8bfae0cfa3b..f08ec698351 100644
--- a/src/mongo/idl/idl_test.cpp
+++ b/src/mongo/idl/idl_test.cpp
@@ -340,15 +340,15 @@ TEST(IDLOneTypeTests, TestNegativeRequiredUndefinedTypes) {
// Mixed: test a type that accepts multiple bson types
-TEST(IDLOneTypeTests, TestSafeInt32) {
- TestParse<One_safeint32, NumberInt, StringData, String>("test_value");
- TestParse<One_safeint32, NumberInt, std::int32_t, NumberInt>(123);
- TestParse<One_safeint32, NumberLong, std::int64_t, NumberLong>(456);
- TestParse<One_safeint32, NumberDouble, double, NumberDouble>(3.14159);
- TestParse<One_safeint32, NumberInt, bool, Bool>(true);
- TestParse<One_safeint32, NumberInt, OID, jstOID>(OID::max());
- TestParse<One_safeint32, NumberInt, Date_t, Date>(Date_t::now());
- TestParse<One_safeint32, NumberInt, Timestamp, bsonTimestamp>(Timestamp::max());
+TEST(IDLOneTypeTests, TestSafeInt64) {
+ TestParse<One_safeint64, NumberInt, StringData, String>("test_value");
+ TestParse<One_safeint64, NumberInt, std::int32_t, NumberInt>(123);
+ TestParse<One_safeint64, NumberLong, std::int64_t, NumberLong>(456);
+ TestParse<One_safeint64, NumberDouble, double, NumberDouble>(3.14159);
+ TestParse<One_safeint64, NumberInt, bool, Bool>(true);
+ TestParse<One_safeint64, NumberInt, OID, jstOID>(OID::max());
+ TestParse<One_safeint64, NumberInt, Date_t, Date>(Date_t::now());
+ TestParse<One_safeint64, NumberInt, Timestamp, bsonTimestamp>(Timestamp::max());
}
// Mixed: test a type that accepts NamespaceString
@@ -1093,7 +1093,7 @@ TEST(IDLArrayTests, TestArraysOfComplexTypes) {
);
auto testStruct = Complex_array_fields::parse(ctxt, testDoc);
- assert_same_types<decltype(testStruct.getField1()), const std::vector<std::int32_t>&>();
+ assert_same_types<decltype(testStruct.getField1()), const std::vector<std::int64_t>&>();
assert_same_types<decltype(testStruct.getField2()),
const std::vector<mongo::NamespaceString>&>();
assert_same_types<decltype(testStruct.getField3()), const std::vector<mongo::AnyBasicType>&>();
@@ -1104,7 +1104,7 @@ TEST(IDLArrayTests, TestArraysOfComplexTypes) {
const std::vector<mongo::idl::import::One_string>&>();
assert_same_types<decltype(testStruct.getField1o()),
- const boost::optional<std::vector<std::int32_t>>&>();
+ const boost::optional<std::vector<std::int64_t>>&>();
assert_same_types<decltype(testStruct.getField2o()),
const boost::optional<std::vector<mongo::NamespaceString>>&>();
assert_same_types<decltype(testStruct.getField3o()),
@@ -1116,7 +1116,7 @@ TEST(IDLArrayTests, TestArraysOfComplexTypes) {
assert_same_types<decltype(testStruct.getField6o()),
const boost::optional<std::vector<mongo::idl::import::One_string>>&>();
- std::vector<std::int32_t> field1{1, 2, 3};
+ std::vector<std::int64_t> field1{1, 2, 3};
ASSERT_TRUE(field1 == testStruct.getField1());
std::vector<NamespaceString> field2{{"a", "b"}, {"c", "d"}};
ASSERT_TRUE(field2 == testStruct.getField2());
diff --git a/src/mongo/idl/unittest.idl b/src/mongo/idl/unittest.idl
index 4f797cc67e0..7ee09db434e 100644
--- a/src/mongo/idl/unittest.idl
+++ b/src/mongo/idl/unittest.idl
@@ -283,10 +283,10 @@ structs:
#
##################################################################################################
- one_safeint32:
- description: UnitTest for a single safeInt32
+ one_safeint64:
+ description: UnitTest for a single safeInt64
fields:
- value: safeInt32
+ value: safeInt64
##################################################################################################
#
@@ -295,7 +295,7 @@ structs:
##################################################################################################
default_values:
- description: UnitTest for a single safeInt32
+ description: UnitTest for default values
fields:
V_string:
type: string
@@ -392,7 +392,7 @@ structs:
description: UnitTest for arrays of complex optional and non-optional simple types
fields:
field1:
- type: array<safeInt32>
+ type: array<safeInt64>
field2:
type: array<namespacestring>
field3:
@@ -404,7 +404,7 @@ structs:
field6:
type: array<one_string>
field1o:
- type: array<safeInt32>
+ type: array<safeInt64>
optional: true
field2o:
type: array<namespacestring>