diff options
author | Eric Milkie <milkie@10gen.com> | 2014-08-12 08:44:03 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2014-08-12 13:23:31 -0400 |
commit | 91e1ec144205e140272b2ed9560accf634c4e93b (patch) | |
tree | 992e0769002d49788c65d82fd64e156dda64cb59 | |
parent | 89d34fd3eb9b21dab1243363e14f5f5ef6a430ff (diff) | |
download | mongo-91e1ec144205e140272b2ed9560accf634c4e93b.tar.gz |
SERVER-12209 _id prohibitions
Prohibit _id of type Array or Undefined.
Also, if _id is an Object, recursively check the object for $fieldnames.
-rw-r--r-- | src/mongo/db/instance.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index b95bcb1bfea..cf3d0849d06 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -784,10 +784,23 @@ namespace mongo { // check no $ modifiers. note we only check top level. // (scanning deep would be quite expensive) uassert( 13511, "document to insert can't have $ fields", e.fieldName()[0] != '$' ); - - // check no regexp for _id (SERVER-9502) + if (str::equals(e.fieldName(), "_id")) { + // check no regexp for _id (SERVER-9502) uassert(16824, "can't use a regex for _id", e.type() != RegEx); + + uassert(ErrorCodes::BadValue, + "can't use an undefined for _id", + e.type() != Undefined ); + + uassert(ErrorCodes::BadValue, + "can't use an array for _id", + e.type() != Array); + + if ( e.type() == Object ) { + BSONObj obj = e.Obj(); + uassert(ErrorCodes::BadValue, "illegal object for _id", obj.okForStorage()); + } } } } |