summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2015-03-09 23:34:35 -0400
committerDan Pasette <dan@mongodb.com>2015-03-09 23:59:25 -0400
commitcd340fc70c2885c35b6e56b11dbcf7aaca011085 (patch)
treeadf9e8122fed3babc38fc40f18f35d2ee25babfd
parentaa0d74203b5fcc43425e08af12cf27542be7c10a (diff)
downloadmongo-cd340fc70c2885c35b6e56b11dbcf7aaca011085.tar.gz
SERVER-17521: improve createIndex validation of empty name
(cherry picked from commit 245ff2fcb2e01f549ae1b0e7aa0716dcdce8765d)
-rw-r--r--jstests/core/create_indexes.js6
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp3
2 files changed, 9 insertions, 0 deletions
diff --git a/jstests/core/create_indexes.js b/jstests/core/create_indexes.js
index 7f003006388..5ab76240d27 100644
--- a/jstests/core/create_indexes.js
+++ b/jstests/core/create_indexes.js
@@ -104,6 +104,12 @@
assert.eq( 6, t.getIndexes().length );
+ res = t.runCommand( "createIndexes",
+ { indexes : [ { key : { "x" : 1 }, name : "" } ] } );
+ assert( !res.ok )
+
+ assert.eq( 6, t.getIndexes().length );
+
//
// Test that v0 indexes can only be created with mmapv1
//
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 24736eb590b..e8321857d5a 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -508,6 +508,9 @@ namespace {
if (name.find('\0') != std::string::npos)
return Status(ErrorCodes::CannotCreateIndex, "index names cannot contain NUL bytes");
+ if (name.empty())
+ return Status(ErrorCodes::CannotCreateIndex, "index names cannot be empty");
+
const std::string indexNamespace = IndexDescriptor::makeIndexNamespace( nss.ns(), name );
if ( indexNamespace.length() > NamespaceString::MaxNsLen )
return Status( ErrorCodes::CannotCreateIndex,