diff options
-rw-r--r-- | src/mongo/db/commands/collection_to_capped.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/commands/compact.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/commands/drop_indexes.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/commands/find_and_modify.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/commands/touch.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/geo/haystack.cpp | 8 |
8 files changed, 52 insertions, 17 deletions
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 6be8e0d7cd5..9e0f2615038 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -193,7 +193,7 @@ namespace mongo { virtual std::vector<BSONObj> stopIndexBuilds(OperationContext* opCtx, Database* db, const BSONObj& cmdObj) { - std::string collName = cmdObj.firstElement().valuestr(); + std::string collName = cmdObj.firstElement().valuestrsafe(); std::string ns = db->name() + "." + collName; IndexCatalog::IndexKillCriteria criteria; diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index ca45cb9b5b8..b2bbd0d33dc 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -76,7 +76,7 @@ namespace mongo { virtual std::vector<BSONObj> stopIndexBuilds(OperationContext* opCtx, Database* db, const BSONObj& cmdObj) { - std::string coll = cmdObj.firstElement().valuestr(); + std::string coll = cmdObj.firstElement().valuestrsafe(); std::string ns = db->name() + "." + coll; IndexCatalog::IndexKillCriteria criteria; @@ -85,8 +85,8 @@ namespace mongo { } virtual bool run(OperationContext* txn, const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - string coll = cmdObj.firstElement().valuestr(); - if( coll.empty() || db.empty() ) { + const std::string coll = cmdObj.firstElement().valuestrsafe(); + if (coll.empty()) { errmsg = "no collection name specified"; return false; } diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 291a7f0de6f..9a05497f944 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -74,7 +74,7 @@ namespace mongo { virtual std::vector<BSONObj> stopIndexBuilds(OperationContext* opCtx, Database* db, const BSONObj& cmdObj) { - std::string toDeleteNs = db->name() + "." + cmdObj.firstElement().valuestr(); + std::string toDeleteNs = db->name() + "." + cmdObj.firstElement().valuestrsafe(); Collection* collection = db->getCollection(opCtx, toDeleteNs); IndexCatalog::IndexKillCriteria criteria; @@ -121,8 +121,13 @@ namespace mongo { BSONObj& jsobj, string& errmsg, BSONObjBuilder& anObjBuilder) { - BSONElement e = jsobj.firstElement(); - const string toDeleteNs = dbname + '.' + e.valuestr(); + const std::string coll = jsobj.firstElement().valuestrsafe(); + if (coll.empty()) { + errmsg = "no collection name specified"; + return false; + } + + const std::string toDeleteNs = dbname + '.' + coll; if (!serverGlobalParams.quiet) { LOG(0) << "CMD: dropIndexes " << toDeleteNs << endl; } diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 6dbd7cc7c6c..d3a1f3d25ea 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -73,7 +73,13 @@ namespace mongo { bool runNoDirectClient( OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { verify( cmdObj["sort"].eoo() ); - const string ns = dbname + '.' + cmdObj.firstElement().valuestr(); + const std::string coll = cmdObj.firstElement().valuestrsafe(); + if (coll.empty()) { + errmsg = "no collection name specified"; + return false; + } + + const std::string ns = dbname + '.' + coll; BSONObj query = cmdObj.getObjectField("query"); BSONObj fields = cmdObj.getObjectField("fields"); @@ -368,7 +374,13 @@ namespace mongo { return runNoDirectClient(txn, dbname, cmdObj, x, errmsg, result, y); } - const string ns = dbname + '.' + cmdObj.firstElement().valuestr(); + const std::string coll = cmdObj.firstElement().valuestrsafe(); + if (coll.empty()) { + errmsg = "no collection name specified"; + return false; + } + + const std::string ns = dbname + '.' + coll; BSONObj origQuery = cmdObj.getObjectField("query"); // defaults to {} Query q (origQuery); diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index eb671b39467..0dfdf942d5e 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -250,7 +250,7 @@ namespace mongo { Config::Config( const string& _dbname , const BSONObj& cmdObj ) { dbname = _dbname; - ns = dbname + "." + cmdObj.firstElement().valuestr(); + ns = dbname + "." + cmdObj.firstElement().valuestrsafe(); verbose = cmdObj["verbose"].trueValue(); jsMode = cmdObj["jsMode"].trueValue(); diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index 34cdc891c78..115b69c0d38 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -79,8 +79,8 @@ namespace mongo { string& errmsg, BSONObjBuilder& result, bool fromRepl) { - string coll = cmdObj.firstElement().valuestr(); - if( coll.empty() || dbname.empty() ) { + const std::string coll = cmdObj.firstElement().valuestrsafe(); + if (coll.empty()) { errmsg = "no collection name specified"; return false; } diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 76b37796417..083e0728522 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -451,7 +451,7 @@ namespace mongo { virtual std::vector<BSONObj> stopIndexBuilds(OperationContext* opCtx, Database* db, const BSONObj& cmdObj) { - std::string nsToDrop = db->name() + '.' + cmdObj.firstElement().valuestr(); + std::string nsToDrop = db->name() + '.' + cmdObj.firstElement().valuestrsafe(); IndexCatalog::IndexKillCriteria criteria; criteria.ns = nsToDrop; @@ -459,7 +459,13 @@ namespace mongo { } virtual bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - const string nsToDrop = dbname + '.' + cmdObj.firstElement().valuestr(); + const std::string collToDrop = cmdObj.firstElement().valuestrsafe(); + if (collToDrop.empty()) { + errmsg = "no collection name specified"; + return false; + } + + const std::string nsToDrop = dbname + '.' + collToDrop; if (!serverGlobalParams.quiet) { LOG(0) << "CMD: drop " << nsToDrop << endl; } @@ -562,7 +568,7 @@ namespace mongo { return appendCommandStatus( result, status ); } - const string ns = dbname + '.' + firstElt.valuestr(); + const std::string ns = dbname + '.' + firstElt.valuestrsafe(); // Build options object from remaining cmdObj elements. BSONObjBuilder optionsBuilder; @@ -984,7 +990,13 @@ namespace mongo { } bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { - const string ns = dbname + "." + jsobj.firstElement().valuestr(); + const std::string collName = jsobj.firstElement().valuestrsafe(); + if (collName.empty()) { + errmsg = "no collection name specified"; + return false; + } + + const std::string ns = dbname + "." + collName; Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); WriteUnitOfWork wunit(txn); diff --git a/src/mongo/db/geo/haystack.cpp b/src/mongo/db/geo/haystack.cpp index aad8bca021f..7b0257d43a1 100644 --- a/src/mongo/db/geo/haystack.cpp +++ b/src/mongo/db/geo/haystack.cpp @@ -69,7 +69,13 @@ namespace mongo { bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - const string ns = dbname + "." + cmdObj.firstElement().valuestr(); + const std::string coll = cmdObj.firstElement().valuestrsafe(); + if (coll.empty()) { + errmsg = "no collection name specified"; + return false; + } + + const std::string ns = dbname + "." + coll; AutoGetCollectionForRead ctx(txn, ns); Collection* collection = ctx.getCollection(); |