summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_leaf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_leaf.cpp')
-rw-r--r--src/mongo/db/matcher/expression_leaf.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_leaf.cpp b/src/mongo/db/matcher/expression_leaf.cpp
index ffe3a660a28..b1ca9d30342 100644
--- a/src/mongo/db/matcher/expression_leaf.cpp
+++ b/src/mongo/db/matcher/expression_leaf.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/query/collation/collator_interface.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/mongoutils/str.h"
+#include "mongo/util/text.h"
namespace mongo {
@@ -226,6 +227,13 @@ Status RegexMatchExpression::init(StringData path, StringData regex, StringData
_regex = regex.toString();
_flags = options.toString();
+
+ // isValidUTF8() checks for UTF-8 which does not map to a series of codepoints but does not
+ // check the validity of the code points themselves. These situations do not cause problems
+ // downstream so we do not do additional work to enforce that the code points are valid.
+ uassert(
+ 5108300, "Regular expression is invalid UTF-8", isValidUTF8(_regex) && isValidUTF8(_flags));
+
_re.reset(new pcrecpp::RE(_regex.c_str(), flags2options(_flags.c_str())));
return setPath(path);