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

Handle regular expression parse errors without seg faulting

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.2
    • Affects Version/s: None
    • Component/s: JavaScript, Shell
    • Environment:
    • ALL
    • Hide

      root@testvm1:~# /opt/mongodb/bin/mongo
      MongoDB shell version: 2.4.3
      connecting to: test
      mongos> db.test_coll.insert([

      {"name":"mihai"}

      ,

      {"name":"foo"}

      ,

      {"name":"bar"}

      ])
      mongos> db.test_coll.count()
      3
      mongos> db.test_coll.find({"name" : {$regex: "(?i)^mih"}}).explain()
      {
      "cursor" : "BasicCursor",
      "isMultiKey" : false,
      "n" : 1,
      "nscannedObjects" : 3,
      "nscanned" : 3,
      "nscannedObjectsAllPlans" : 3,
      "nscannedAllPlans" : 3,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "millis" : 0,
      "indexBounds" : {

      },
      "server" : "testvm1:2001",
      "millis" : 0
      }
      mongos> db.test_coll.ensureIndex(

      {"name":1}

      )
      mongos> db.test_coll.getIndexes()
      [
      {
      "v" : 1,
      "key" :

      { "_id" : 1 }

      ,
      "ns" : "test.test_coll",
      "name" : "id"
      },
      {
      "v" : 1,
      "key" :

      { "name" : 1 }

      ,
      "ns" : "test.test_coll",
      "name" : "name_1"
      }
      ]
      mongos> db.test_coll.find({"name" : {$regex: "(?i)^mih"}}).explain()
      Wed May 29 11:04:05.464 mongo got signal 11 (Segmentation fault), stack trace:

      Wed May 29 11:04:05.469 0x746df1 0x5dce32 0x7fee00e724f0 0x99d71c 0x7f3457 0x6ee4d3 0x6ee4c6 0x6f2b30 0x990293 0x98fc73 0x9ecc30 0x34df04206362
      /opt/mongodb/bin/mongo(_ZN5mongo15printStackTraceERSo+0x21) [0x746df1]
      /opt/mongodb/bin/mongo(_Z12quitAbruptlyi+0x382) [0x5dce32]
      /lib/x86_64-linux-gnu/libc.so.6(+0x324f0) [0x7fee00e724f0]
      /opt/mongodb/bin/mongo(_ZN2v88internal8JSObject10SetElementENS0_6HandleIS1_EEjNS2_INS0_6ObjectEEE18PropertyAttributesNS0_14StrictModeFlagENS0_15SetPropertyModeE+0x7c) [0x99d71c]
      /opt/mongodb/bin/mongo(_ZN2v86Object3SetEjNS_6HandleINS_5ValueEEE+0xf7) [0x7f3457]
      /opt/mongodb/bin/mongo(_ZN5mongo7V8Scope16mongoToV8ElementERKNS_11BSONElementEb+0x1113) [0x6ee4d3]
      /opt/mongodb/bin/mongo(_ZN5mongo7V8Scope16mongoToV8ElementERKNS_11BSONElementEb+0x1106) [0x6ee4c6]
      /opt/mongodb/bin/mongo() [0x6f2b30]
      /opt/mongodb/bin/mongo(_ZN2v88internal8JSObject35GetPropertyAttributeWithInterceptorEPS1_PNS0_6StringEb+0x453) [0x990293]
      /opt/mongodb/bin/mongo(_ZN2v88internal10JSReceiver32GetPropertyAttributeWithReceiverEPS1_PNS0_6StringE+0xb3) [0x98fc73]
      /opt/mongodb/bin/mongo(_ZN2v88internal19Runtime_HasPropertyENS0_9ArgumentsEPNS0_7IsolateE+0x70) [0x9ecc30]
      [0x34df04206362]

      root@testvm1:~#

      Show
      root@testvm1:~# /opt/mongodb/bin/mongo MongoDB shell version: 2.4.3 connecting to: test mongos> db.test_coll.insert([ {"name":"mihai"} , {"name":"foo"} , {"name":"bar"} ]) mongos> db.test_coll.count() 3 mongos> db.test_coll.find({"name" : {$regex: "(?i)^mih"}}).explain() { "cursor" : "BasicCursor", "isMultiKey" : false, "n" : 1, "nscannedObjects" : 3, "nscanned" : 3, "nscannedObjectsAllPlans" : 3, "nscannedAllPlans" : 3, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { }, "server" : "testvm1:2001", "millis" : 0 } mongos> db.test_coll.ensureIndex( {"name":1} ) mongos> db.test_coll.getIndexes() [ { "v" : 1, "key" : { "_id" : 1 } , "ns" : "test.test_coll", "name" : " id " }, { "v" : 1, "key" : { "name" : 1 } , "ns" : "test.test_coll", "name" : "name_1" } ] mongos> db.test_coll.find({"name" : {$regex: "(?i)^mih"}}).explain() Wed May 29 11:04:05.464 mongo got signal 11 (Segmentation fault), stack trace: Wed May 29 11:04:05.469 0x746df1 0x5dce32 0x7fee00e724f0 0x99d71c 0x7f3457 0x6ee4d3 0x6ee4c6 0x6f2b30 0x990293 0x98fc73 0x9ecc30 0x34df04206362 /opt/mongodb/bin/mongo(_ZN5mongo15printStackTraceERSo+0x21) [0x746df1] /opt/mongodb/bin/mongo(_Z12quitAbruptlyi+0x382) [0x5dce32] /lib/x86_64-linux-gnu/libc.so.6(+0x324f0) [0x7fee00e724f0] /opt/mongodb/bin/mongo(_ZN2v88internal8JSObject10SetElementENS0_6HandleIS1_EEjNS2_INS0_6ObjectEEE18PropertyAttributesNS0_14StrictModeFlagENS0_15SetPropertyModeE+0x7c) [0x99d71c] /opt/mongodb/bin/mongo(_ZN2v86Object3SetEjNS_6HandleINS_5ValueEEE+0xf7) [0x7f3457] /opt/mongodb/bin/mongo(_ZN5mongo7V8Scope16mongoToV8ElementERKNS_11BSONElementEb+0x1113) [0x6ee4d3] /opt/mongodb/bin/mongo(_ZN5mongo7V8Scope16mongoToV8ElementERKNS_11BSONElementEb+0x1106) [0x6ee4c6] /opt/mongodb/bin/mongo() [0x6f2b30] /opt/mongodb/bin/mongo(_ZN2v88internal8JSObject35GetPropertyAttributeWithInterceptorEPS1_PNS0_6StringEb+0x453) [0x990293] /opt/mongodb/bin/mongo(_ZN2v88internal10JSReceiver32GetPropertyAttributeWithReceiverEPS1_PNS0_6StringE+0xb3) [0x98fc73] /opt/mongodb/bin/mongo(_ZN2v88internal19Runtime_HasPropertyENS0_9ArgumentsEPNS0_7IsolateE+0x70) [0x9ecc30] [0x34df04206362] root@testvm1:~#

      Do not seg fault when there is an error in parsing/creating regular expressions in javascript.

      Old description
      MongoDB shell client crashes when running a find(...).explain() query on a field which is indexed.
      Reproduced on Debian 7 64 bit, on both MongoDB 2.4.1 and 2.4.3. Reproduced on both MongoDB standalone and mongos + replica set environment.

            Assignee:
            tad Tad Marshall
            Reporter:
            locksmith Mihai Lacatusu
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: