summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/validate.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-12-05 11:19:48 -0500
committerDavid Storch <david.storch@10gen.com>2016-12-09 17:59:52 -0500
commit7cf929f25638e4ad9525775c8ea0e18f3c86faf5 (patch)
tree42328072009a72ce73f1c5bffe60f0c36ee0d492 /src/mongo/db/commands/validate.cpp
parent586ac20773ff7dc18cabf329c238bf261e00387d (diff)
downloadmongo-7cf929f25638e4ad9525775c8ea0e18f3c86faf5.tar.gz
SERVER-24128 reject embedded null bytes in namespace string parsing
Diffstat (limited to 'src/mongo/db/commands/validate.cpp')
-rw-r--r--src/mongo/db/commands/validate.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index f1d5ff4a349..9622947e59f 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -87,9 +87,8 @@ public:
return true;
}
- string ns = dbname + "." + cmdObj.firstElement().valuestrsafe();
+ const NamespaceString nss(parseNsCollectionRequired(dbname, cmdObj));
- NamespaceString ns_string(ns);
const bool full = cmdObj["full"].trueValue();
const bool scanData = cmdObj["scandata"].trueValue();
@@ -101,20 +100,20 @@ public:
level = kValidateRecordStore;
}
- if (!ns_string.isNormal() && full) {
+ if (!nss.isNormal() && full) {
errmsg = "Can only run full validate on a regular collection";
return false;
}
if (!serverGlobalParams.quiet) {
- LOG(0) << "CMD: validate " << ns;
+ LOG(0) << "CMD: validate " << nss.ns();
}
- AutoGetDb ctx(txn, ns_string.db(), MODE_IX);
- Lock::CollectionLock collLk(txn->lockState(), ns_string.ns(), MODE_X);
- Collection* collection = ctx.getDb() ? ctx.getDb()->getCollection(ns_string) : NULL;
+ AutoGetDb ctx(txn, nss.db(), MODE_IX);
+ Lock::CollectionLock collLk(txn->lockState(), nss.ns(), MODE_X);
+ Collection* collection = ctx.getDb() ? ctx.getDb()->getCollection(nss) : NULL;
if (!collection) {
- if (ctx.getDb() && ctx.getDb()->getViewCatalog()->lookup(txn, ns_string.ns())) {
+ if (ctx.getDb() && ctx.getDb()->getViewCatalog()->lookup(txn, nss.ns())) {
errmsg = "Cannot validate a view";
return appendCommandStatus(result, {ErrorCodes::CommandNotSupportedOnView, errmsg});
}
@@ -123,7 +122,7 @@ public:
return false;
}
- result.append("ns", ns);
+ result.append("ns", nss.ns());
ValidateResults results;
Status status = collection->validate(txn, level, &results, &result);