diff options
author | Arun Banala <arun.banala@mongodb.com> | 2019-03-28 14:36:10 +0000 |
---|---|---|
committer | Arun Banala <arun.banala@mongodb.com> | 2019-04-01 15:44:19 +0100 |
commit | 1d8ddd2d2d480bc0b840b506c3630c82be8c09a2 (patch) | |
tree | 0261c9dffbe39bd7bfb0348e8b029b0b5446f8bd /src/mongo/db | |
parent | b6761b00896e78c1e30e565ee82752bcc7d252f0 (diff) | |
download | mongo-1d8ddd2d2d480bc0b840b506c3630c82be8c09a2.tar.gz |
SERVER-40343 Better handling of errors from PCRE in $regex expressions
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/pipeline/expression_test.cpp | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index cebc922084f..f842c88c1c9 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -5681,10 +5681,15 @@ public: 0, // No need to overwrite the options set during pcre_compile. &_capturesBuffer.front(), _capturesBuffer.size()); - // The 'execResult' will be '(_numCaptures + 1)' if there is a match, negative if there is - // no match, and zero if _capturesBuffer's capacity is not sufficient to hold all the - // results; the latter scenario should never actually occur. - invariant(execResult < 0 || execResult == _numCaptures + 1); + // The 'execResult' will be (_numCaptures + 1) if there is a match, -1 if there is no + // match, negative if there is an error during execution, and zero if _capturesBuffer's + // capacity is not sufficient to hold all the results. The latter scenario should never + // occur. + uassert( + 51156, + str::stream() << "Error occurred while executing the regular expression. Result code:" + << execResult, + execResult == -1 || execResult == (_numCaptures + 1)); return execResult; } diff --git a/src/mongo/db/pipeline/expression_test.cpp b/src/mongo/db/pipeline/expression_test.cpp index d0ee16fc2fa..5c2426217ab 100644 --- a/src/mongo/db/pipeline/expression_test.cpp +++ b/src/mongo/db/pipeline/expression_test.cpp @@ -6019,8 +6019,8 @@ TEST(ExpressionRegexFindAllTest, InvalidUTF8InInput) { intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); ExpressionRegexFindAll regexF(expCtx); regexF.addOperand(ExpressionConstant::create(expCtx, input)); - // Verify no match if there is an invalid UTF-8 character in input. - ASSERT_VALUE_EQ(regexF.evaluate(Document()), Value(std::vector<Value>())); + // Verify that PCRE will error during execution if input is not a valid UTF-8. + ASSERT_THROWS_CODE(regexF.evaluate(Document()), DBException, 51156); } TEST(ExpressionRegexFindAllTest, InvalidUTF8InRegex) { |