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

Server should error on invalid regex match expressions

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc0
    • Affects Version/s: 2.6.12, 3.0.15, 3.2.16, 3.4.7
    • Component/s: Querying
    • Labels:
    • Fully Compatible
    • ALL
    • Query 2017-10-02

      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.

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

              Created:
              Updated:
              Resolved: