Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

check for bad $set where set to an object with a . SERVER-261

  • Loading branch information...
commit 53b5dae92e8c045f6aa94add14dc0564ee9ee6e9 1 parent 6830dd0
@erh erh authored
Showing with 14 additions and 2 deletions.
  1. +1 −0  db/update.cpp
  2. +12 −1 db/update.h
  3. +1 −1  jstests/set1.js
View
1  db/update.cpp
@@ -57,6 +57,7 @@ namespace mongo {
}
case SET: {
+ _checkForAppending( elt );
b.appendAs( elt , shortFieldName );
break;
}
View
13 db/update.h
@@ -146,6 +146,17 @@ namespace mongo {
bb.append( elt );
bb.done();
}
+
+ void _checkForAppending( BSONElement& e ){
+ if ( e.type() == Object ){
+ // this is a tiny bit slow, but rare and important
+ // only when setting something TO an object, not setting something in an object
+ // and it checks for { $set : { x : { 'a.b' : 1 } } }
+ // which is feel has been common
+ uassert( 12527 , "not okForStorage" , e.embeddedObject().okForStorage() );
+ }
+ }
+
};
class ModSet {
@@ -173,7 +184,6 @@ namespace mongo {
void _appendNewFromMods( const string& root , Mod& m , BSONObjBuilder& b , set<string>& onedownseen );
void appendNewFromMod( Mod& m , BSONObjBuilder& b ){
-
switch ( m.op ){
case Mod::PUSH: {
@@ -198,6 +208,7 @@ namespace mongo {
case Mod::INC:
case Mod::SET: {
+ m._checkForAppending( m.elt );
b.appendAs( m.elt, m.shortFieldName );
break;
}
View
2  jstests/set1.js
@@ -4,6 +4,6 @@ t.drop();
t.insert( { _id : 1, emb : {} });
t.update( { _id : 1 }, { $set : { emb : { 'a.dot' : 'data'} }});
+assert.eq( { _id : 1 , emb : {} } , t.findOne() , "A" );
-printjson( t.findOne() ); // SERVER-261
Please sign in to comment.
Something went wrong with that request. Please try again.