Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-1705 validate op type with regex

  • Loading branch information...
commit 30c59fa55079088d1d60a318e5e3f526f600856e 1 parent fccae83
@astaple astaple authored
View
3  db/queryutil.cpp
@@ -181,10 +181,12 @@ namespace mongo {
if ( e.eoo() )
return;
+ int op = e.getGtLtOp();
if ( e.type() == RegEx
|| (e.type() == Object && !e.embeddedObject()["$regex"].eoo())
)
{
+ uassert( 13454, "invalid regular expression operator", op == BSONObj::Equality || op == BSONObj::opREGEX );
if ( !isNot ) { // no optimization for negated regex - we could consider creating 2 intervals comprising all nonmatching prefixes
const string r = simpleRegex(e);
if ( r.size() ) {
@@ -216,7 +218,6 @@ namespace mongo {
}
return;
}
- int op = e.getGtLtOp();
if ( isNot ) {
switch( op ) {
case BSONObj::Equality:
View
22 jstests/ne2.js
@@ -19,25 +19,3 @@ e = t.find( { a: { $gt: -1, $lt: 1, $ne: 0 } } ).explain();
assert.eq( "BtreeCursor a_1 multi", e.cursor );
assert.eq( { a: [ [ -1, 0 ], [ 0, 1 ] ] }, e.indexBounds );
assert.eq( 3, e.nscanned );
-
-//e = t.find( { a: { $not: { $all: [0] }} } ).explain( true );
-//assert.eq( "BtreeCursor a_1 multi", e.cursor );
-//assert.eq( 0, e.indexBounds.a[ 0 ][ 1 ] );
-//assert.eq( 0, e.indexBounds.a[ 1 ][ 0 ] );
-//assert.eq( 3, e.nscanned );
-//
-//e = t.find( { a: { $gt: -1, $lt: 1, $not: { $all: [ 0 ] } } } ).explain();
-//assert.eq( "BtreeCursor a_1 multi", e.cursor );
-//assert.eq( { a: [ [ -1, 0 ], [ 0, 1 ] ] }, e.indexBounds );
-//assert.eq( 3, e.nscanned );
-//
-//e = t.find( { a: { $nin: [ 0 ] } } ).explain( true );
-//assert.eq( "BtreeCursor a_1 multi", e.cursor );
-//assert.eq( 0, e.indexBounds.a[ 0 ][ 1 ] );
-//assert.eq( 0, e.indexBounds.a[ 1 ][ 0 ] );
-//assert.eq( 3, e.nscanned );
-//
-//e = t.find( { a: { $gt: -1, $lt: 1, $nin: [ 0 ] } } ).explain();
-//assert.eq( "BtreeCursor a_1 multi", e.cursor );
-//assert.eq( { a: [ [ -1, 0 ], [ 0, 1 ] ] }, e.indexBounds );
-//assert.eq( 3, e.nscanned );
View
12 jstests/ne3.js
@@ -0,0 +1,12 @@
+// don't allow most operators with regex
+
+t = db.jstests_ne3;
+t.drop();
+
+assert.throws( function() { t.findOne( { t: { $ne: /a/ } } ); } );
+assert.throws( function() { t.findOne( { t: { $gt: /a/ } } ); } );
+assert.throws( function() { t.findOne( { t: { $gte: /a/ } } ); } );
+assert.throws( function() { t.findOne( { t: { $lt: /a/ } } ); } );
+assert.throws( function() { t.findOne( { t: { $lte: /a/ } } ); } );
+
+assert.eq( 0, t.count( { t: { $in: [ /a/ ] } } ) );
View
2  jstests/regex9.js
@@ -1,5 +1,5 @@
-t = db.regex3;
+t = db.regex9;
t.drop();
t.insert( { _id : 1 , a : [ "a" , "b" , "c" ] } )
View
4 mongo.xcodeproj/project.pbxproj
@@ -463,6 +463,8 @@
938A7A480F54873600FB7A07 /* reccache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reccache.h; sourceTree = "<group>"; };
938A7A490F54873600FB7A07 /* reci.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reci.h; sourceTree = "<group>"; };
938A7A4A0F54873600FB7A07 /* recstore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recstore.h; sourceTree = "<group>"; };
+ 938D48DB122C87A2001D83EE /* nin2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = nin2.js; sourceTree = "<group>"; };
+ 938D493D122C99A3001D83EE /* ne3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ne3.js; sourceTree = "<group>"; };
938E5EB3110E1ED700A8760A /* repair.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = repair.js; sourceTree = "<group>"; };
938E60AC110F734800A8760A /* directoryperdb.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = directoryperdb.js; sourceTree = "<group>"; };
938E639B110FC66900A8760A /* auth1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = auth1.js; sourceTree = "<group>"; };
@@ -836,6 +838,8 @@
934BEB9A10DFFA9600178102 /* jstests */ = {
isa = PBXGroup;
children = (
+ 938D493D122C99A3001D83EE /* ne3.js */,
+ 938D48DB122C87A2001D83EE /* nin2.js */,
939329BF12244845005EB75E /* ne2.js */,
93C46E64121A086500382E61 /* indexj.js */,
93C46E021219AB8E00382E61 /* update_arraymatch6.js */,
Please sign in to comment.
Something went wrong with that request. Please try again.