summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuoxin Xu <ruoxin.xu@mongodb.com>2021-10-05 08:21:46 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-05 08:58:51 +0000
commit4bb27a5a497b002fa0a70234ffd89c5a24a22612 (patch)
treeeddbd5110d0a6bf6921bc10d0fba29e453a39b60
parenta73cbaa31af52f1f8de9c35f579c69bb384a9501 (diff)
downloadmongo-4bb27a5a497b002fa0a70234ffd89c5a24a22612.tar.gz
SERVER-59873 Return correct Status when failed parsing $_internalBucketGeoWithin
-rw-r--r--src/mongo/db/matcher/expression_parser.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp
index a1d88ab3949..4e24ef321c9 100644
--- a/src/mongo/db/matcher/expression_parser.cpp
+++ b/src/mongo/db/matcher/expression_parser.cpp
@@ -1079,11 +1079,20 @@ StatusWithMatchExpression parseInternalBucketGeoWithinMatchExpression(
auto subobj = elem.embeddedObject();
- // Parse the region field, 'withinRegion', to a GeometryContainer.
std::shared_ptr<GeometryContainer> geoContainer = std::make_shared<GeometryContainer>();
- tassert(5776200,
- "$_internalBucketGeoWithin expression must contain 'withinRegion' field",
- subobj.hasField("withinRegion"));
+ if (!subobj.hasField("withinRegion") || !subobj.hasField("field")) {
+ return {ErrorCodes::FailedToParse,
+ str::stream() << InternalBucketGeoWithinMatchExpression::kName
+ << " requires both 'withinRegion' and 'field' field"};
+ }
+
+ if (subobj["withinRegion"].type() != BSONType::Object) {
+ return {ErrorCodes::TypeMismatch,
+ str::stream() << InternalBucketGeoWithinMatchExpression::kName
+ << "'s 'withinRegion' field must be an object"};
+ }
+
+ // Parse the region field, 'withinRegion', to a GeometryContainer.
BSONObjIterator geoIt(subobj["withinRegion"].embeddedObject());
while (geoIt.more()) {
BSONElement elt = geoIt.next();
@@ -1093,10 +1102,13 @@ StatusWithMatchExpression parseInternalBucketGeoWithinMatchExpression(
return status;
}
+ if (subobj["field"].type() != BSONType::String) {
+ return {ErrorCodes::TypeMismatch,
+ str::stream() << InternalBucketGeoWithinMatchExpression::kName
+ << "'s 'field' field must be a string"};
+ }
+
// Parse the field.
- tassert(5776201,
- "$_internalBucketGeoWithin expression must contain 'field' field with a string value",
- subobj.hasField("field") && subobj["field"].type() == BSONType::String);
std::string field = subobj["field"].String();
expCtx->sbeCompatible = false;