summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAdityavardhan Agrawal <aa729@cornell.edu>2022-12-02 20:34:44 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-02 21:56:05 +0000
commit9836a37758bf158652b5664e9ddda961bd548326 (patch)
treea9714738d4fab1122c529bff360e8ff236c8226c /src/mongo
parent6b1381f39315a29215ff347f3c950c1392f71c41 (diff)
downloadmongo-9836a37758bf158652b5664e9ddda961bd548326.tar.gz
SERVER-70867 Add uassert to handle unsafe usage of value::compareValue
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/exec/sbe/stages/sort.cpp2
-rw-r--r--src/mongo/db/query/optimizer/rewrites/const_eval.cpp3
-rw-r--r--src/mongo/db/query/optimizer/syntax/expr.cpp1
-rw-r--r--src/mongo/db/query/optimizer/utils/abt_compare.cpp2
4 files changed, 7 insertions, 1 deletions
diff --git a/src/mongo/db/exec/sbe/stages/sort.cpp b/src/mongo/db/exec/sbe/stages/sort.cpp
index 1443a1d5e67..276c07efaef 100644
--- a/src/mongo/db/exec/sbe/stages/sort.cpp
+++ b/src/mongo/db/exec/sbe/stages/sort.cpp
@@ -136,7 +136,7 @@ void SortStage::makeSorter() {
auto [lhsTag, lhsVal] = lhs.getViewOfValue(idx);
auto [rhsTag, rhsVal] = rhs.getViewOfValue(idx);
auto [tag, val] = value::compareValue(lhsTag, lhsVal, rhsTag, rhsVal);
-
+ uassert(7086700, "Invalid comparison result", tag == value::TypeTags::NumberInt32);
auto result = value::bitcastTo<int32_t>(val);
if (result) {
return _dirs[idx] == value::SortDirection::Descending ? -result : result;
diff --git a/src/mongo/db/query/optimizer/rewrites/const_eval.cpp b/src/mongo/db/query/optimizer/rewrites/const_eval.cpp
index 010ef21125a..603bf407c93 100644
--- a/src/mongo/db/query/optimizer/rewrites/const_eval.cpp
+++ b/src/mongo/db/query/optimizer/rewrites/const_eval.cpp
@@ -310,6 +310,9 @@ void ConstEval::transport(ABT& n, const BinaryOp& op, ABT& lhs, ABT& rhs) {
const auto [compareTag, compareVal] =
sbe::value::compareValue(lhsTag, lhsVal, rhsTag, rhsVal);
+ uassert(7086701,
+ "Invalid comparison result",
+ compareTag == sbe::value::TypeTags::NumberInt32);
const auto cmpVal = sbe::value::bitcastTo<int32_t>(compareVal);
switch (op.op()) {
diff --git a/src/mongo/db/query/optimizer/syntax/expr.cpp b/src/mongo/db/query/optimizer/syntax/expr.cpp
index 3b340381cb6..0fed04069fa 100644
--- a/src/mongo/db/query/optimizer/syntax/expr.cpp
+++ b/src/mongo/db/query/optimizer/syntax/expr.cpp
@@ -119,6 +119,7 @@ Constant::~Constant() {
bool Constant::operator==(const Constant& other) const {
const auto [compareTag, compareVal] = compareValue(_tag, _val, other._tag, other._val);
+ uassert(7086702, "Invalid comparison result", compareTag == sbe::value::TypeTags::NumberInt32);
return sbe::value::bitcastTo<int32_t>(compareVal) == 0;
}
diff --git a/src/mongo/db/query/optimizer/utils/abt_compare.cpp b/src/mongo/db/query/optimizer/utils/abt_compare.cpp
index 77151482d2f..08325dc76a5 100644
--- a/src/mongo/db/query/optimizer/utils/abt_compare.cpp
+++ b/src/mongo/db/query/optimizer/utils/abt_compare.cpp
@@ -95,6 +95,8 @@ private:
const auto [tag, val] = node.get();
const auto [otherTag, otherVal] = other.get();
const auto [compareTag, compareVal] = compareValue(tag, val, otherTag, otherVal);
+ uassert(
+ 7086703, "Invalid comparison result", compareTag == sbe::value::TypeTags::NumberInt32);
return sbe::value::bitcastTo<int32_t>(compareVal);
}