Skip to content

Commit

Permalink
SERVER-12209: check _id for $fields at insert time
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Feb 6, 2014
1 parent efeb3da commit 34d8993
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mongo/db/ops/insert.cpp
Expand Up @@ -80,6 +80,12 @@ namespace mongo {
return StatusWith<BSONObj>( ErrorCodes::BadValue,
"can't use an array for _id" );
}
if ( e.type() == Object ) {
BSONObj o = e.Obj();
Status s = o.storageValidEmbedded();
if ( !s.isOK() )
return StatusWith<BSONObj>( s );
}
}

}
Expand Down
11 changes: 11 additions & 0 deletions src/mongo/dbtests/pdfiletests.cpp
Expand Up @@ -100,6 +100,16 @@ namespace PdfileTests {
ASSERT( a.timestampValue() > 0 );
}
};

class ValidId : public Base {
public:
void run() {
ASSERT( fixDocumentForInsert( BSON( "_id" << 5 ) ).isOK() );
ASSERT( fixDocumentForInsert( BSON( "_id" << BSON( "x" << 5 ) ) ).isOK() );
ASSERT( !fixDocumentForInsert( BSON( "_id" << BSON( "$x" << 5 ) ) ).isOK() );
ASSERT( !fixDocumentForInsert( BSON( "_id" << BSON( "$oid" << 5 ) ) ).isOK() );
}
};
} // namespace Insert

class ExtentSizing {
Expand Down Expand Up @@ -164,6 +174,7 @@ namespace PdfileTests {
void setupTests() {
add< Insert::InsertNoId >();
add< Insert::UpdateDate >();
add< Insert::ValidId >();
add< ExtentSizing >();
}
} myall;
Expand Down

0 comments on commit 34d8993

Please sign in to comment.