mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
don't allow empty collection names SERVER-2314
This commit is contained in:
parent
9d8e3967a9
commit
d60aa255e3
@ -186,7 +186,7 @@ namespace mongo {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(1) << "create collection " << ns << ' ' << options << '\n';
|
log(1) << "create collection " << ns << ' ' << options << endl;
|
||||||
|
|
||||||
/* todo: do this only when we have allocated space successfully? or we could insert with a { ok: 0 } field
|
/* todo: do this only when we have allocated space successfully? or we could insert with a { ok: 0 } field
|
||||||
and then go back and set to ok : 1 after we are done.
|
and then go back and set to ok : 1 after we are done.
|
||||||
@ -1444,7 +1444,7 @@ namespace mongo {
|
|||||||
DiskLoc DataFileMgr::insert(const char *ns, const void *obuf, int len, bool god, const BSONElement &writeId, bool mayAddIndex) {
|
DiskLoc DataFileMgr::insert(const char *ns, const void *obuf, int len, bool god, const BSONElement &writeId, bool mayAddIndex) {
|
||||||
bool wouldAddIndex = false;
|
bool wouldAddIndex = false;
|
||||||
massert( 10093 , "cannot insert into reserved $ collection", god || isANormalNSName( ns ) );
|
massert( 10093 , "cannot insert into reserved $ collection", god || isANormalNSName( ns ) );
|
||||||
uassert( 10094 , "invalid ns", strchr( ns , '.' ) > 0 );
|
uassert( 10094 , str::stream() << "invalid ns: " << ns , isValidNS( ns ) );
|
||||||
const char *sys = strstr(ns, "system.");
|
const char *sys = strstr(ns, "system.");
|
||||||
if ( sys ) {
|
if ( sys ) {
|
||||||
uassert( 10095 , "attempt to insert in reserved database name 'system'", sys != ns);
|
uassert( 10095 , "attempt to insert in reserved database name 'system'", sys != ns);
|
||||||
@ -1961,7 +1961,7 @@ namespace mongo {
|
|||||||
BOOST_CHECK_EXCEPTION( ok = fo.apply(q) );
|
BOOST_CHECK_EXCEPTION( ok = fo.apply(q) );
|
||||||
if ( ok ) {
|
if ( ok ) {
|
||||||
if ( extra != 10 ){
|
if ( extra != 10 ){
|
||||||
log(1) << fo.op() << " file " << q.string() << '\n';
|
log(1) << fo.op() << " file " << q.string() << endl;
|
||||||
log() << " _applyOpToDataFiles() warning: extra == " << extra << endl;
|
log() << " _applyOpToDataFiles() warning: extra == " << extra << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2013,6 +2013,17 @@ namespace mongo {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isValidNS( const StringData& ns ){
|
||||||
|
// TODO: should check for invalid characters
|
||||||
|
|
||||||
|
const char * x = strchr( ns.data() , '.' );
|
||||||
|
if ( ! x )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
x++;
|
||||||
|
return *x > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace mongo
|
} // namespace mongo
|
||||||
|
@ -55,6 +55,8 @@ namespace mongo {
|
|||||||
// -1 if library unavailable.
|
// -1 if library unavailable.
|
||||||
boost::intmax_t freeSpace( const string &path = dbpath );
|
boost::intmax_t freeSpace( const string &path = dbpath );
|
||||||
|
|
||||||
|
bool isValidNS( const StringData& ns );
|
||||||
|
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
class MongoDataFile {
|
class MongoDataFile {
|
||||||
|
@ -425,6 +425,14 @@ namespace BasicTests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NSValidNames {
|
||||||
|
public:
|
||||||
|
void run(){
|
||||||
|
ASSERT( isValidNS( "test.foo" ) );
|
||||||
|
ASSERT( ! isValidNS( "test." ) );
|
||||||
|
ASSERT( ! isValidNS( "test" ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class PtrTests {
|
class PtrTests {
|
||||||
public:
|
public:
|
||||||
@ -592,6 +600,8 @@ namespace BasicTests {
|
|||||||
add< DatabaseValidNames >();
|
add< DatabaseValidNames >();
|
||||||
add< DatabaseOwnsNS >();
|
add< DatabaseOwnsNS >();
|
||||||
|
|
||||||
|
add< NSValidNames >();
|
||||||
|
|
||||||
add< PtrTests >();
|
add< PtrTests >();
|
||||||
|
|
||||||
add< StringSplitterTest >();
|
add< StringSplitterTest >();
|
||||||
|
Loading…
Reference in New Issue
Block a user