Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-30986

Server should error on invalid regex match expressions

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.6.12, 3.0.15, 3.2.16, 3.4.7
    • 3.6.0-rc0
    • Querying
    • Fully Compatible
    • ALL
    • Query 2017-10-02

    Description

      The server accepts invalid regular expressions in the match language. It appears that such invalid regular expressions will match nothing:

      > db.c.drop();
      true
      > db.c.insert({a: 1, b: "["});
      WriteResult({ "nInserted" : 1 })
      > db.c.find({a: 1, b: {$regex: "["}});
      // Empty result set.
      

      In order to fix this, the MatchExpression library should call pcrecpp::RE::error() and check whether the resulting error string is non-empty:

      https://github.com/mongodb/mongo/blob/9f8084f2c87cdbe5616cd5d6d8adb2a8272a504a/src/third_party/pcre-8.41/pcrecpp.h#L526-L528

      This bug appears to affect all versions of the server since at least 2.6.

      Attachments

        Issue Links

          Activity

            People

              blake.oler@mongodb.com Blake Oler
              david.storch@mongodb.com David Storch
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: