summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2013-03-01 14:14:00 -0500
committerMathias Stearn <mathias@10gen.com>2013-03-05 16:30:23 -0500
commit629ed9f2a0bd63fe6640d6497aeee840bd474214 (patch)
treec29897ad6044f504e4b95e75dd29722f8e96b1b2
parent0893701ad4a183589e08d3e00428b6f1d5a37124 (diff)
downloadmongo-629ed9f2a0bd63fe6640d6497aeee840bd474214.tar.gz
SERVER-5826 prevent building an index with a non-existent plugin
-rw-r--r--jstests/bad_index_plugin.js11
-rw-r--r--src/mongo/db/index.cpp9
2 files changed, 18 insertions, 2 deletions
diff --git a/jstests/bad_index_plugin.js b/jstests/bad_index_plugin.js
new file mode 100644
index 00000000000..7d18694664f
--- /dev/null
+++ b/jstests/bad_index_plugin.js
@@ -0,0 +1,11 @@
+// SERVER-5826 ensure you can't build an index with a non-existent plugin
+t = db.bad_index_plugin;
+
+assert.eq(t.ensureIndex({good: 1}), undefined);
+assert.eq(t.getIndexes().length, 2); // good + _id
+
+err = t.ensureIndex({bad: 'bad'});
+assert.neq(err, undefined);
+assert.eq(err.code, 16734);
+
+assert.eq(t.getIndexes().length, 2); // good + _id (no bad)
diff --git a/src/mongo/db/index.cpp b/src/mongo/db/index.cpp
index cee68107b5d..5077faa1894 100644
--- a/src/mongo/db/index.cpp
+++ b/src/mongo/db/index.cpp
@@ -367,8 +367,13 @@ namespace mongo {
}
string pluginName = IndexPlugin::findPluginName( key );
- IndexPlugin * plugin = pluginName.size() ? IndexPlugin::get( pluginName ) : 0;
-
+ IndexPlugin * plugin = NULL;
+ if (pluginName.size()) {
+ plugin = IndexPlugin::get(pluginName);
+ uassert(16734, str::stream() << "Unknown index plugin '" << pluginName << "' "
+ << "in index "<< key
+ , plugin);
+ }
{
BSONObj o = io;