summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Guo <robert.guo@10gen.com>2015-11-11 18:54:35 -0500
committerRobert Guo <robert.guo@10gen.com>2016-01-27 17:14:15 -0500
commite2835f1cbfcd47108bc1c077d886246c96dd5efe (patch)
tree1799f34bed10ce5b503e36bb32c2e1b223b489a4
parent15e8b49669fdb4555acff2431fc9d5add48ca388 (diff)
downloadmongo-e2835f1cbfcd47108bc1c077d886246c96dd5efe.tar.gz
SERVER-21388 validate captrunc argument
-rw-r--r--jstests/noPassthroughWithMongod/capped_truncate.js7
-rw-r--r--src/mongo/db/commands/test_commands.cpp5
2 files changed, 12 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/capped_truncate.js b/jstests/noPassthroughWithMongod/capped_truncate.js
index 1c7771ce0bd..8408ea7294b 100644
--- a/jstests/noPassthroughWithMongod/capped_truncate.js
+++ b/jstests/noPassthroughWithMongod/capped_truncate.js
@@ -17,6 +17,13 @@
autoIndexId: true }));
var t = db.capped_truncate;
+ // It is an error to remove a non-positive number of documents.
+ assert.commandFailed(db.runCommand({ captrunc: "capped_truncate", n: -1 }),
+ "captrunc didn't return an error when attempting to remove a negative " +
+ "number of documents");
+ assert.commandFailed(db.runCommand({ captrunc: "capped_truncate", n: 0 }),
+ "captrunc didn't return an error when attempting to remove 0 documents");
+
for (var j = 1; j <= 10; j++) {
assert.writeOK(t.insert({x:j}));
}
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index fcfafbf5607..485998c4e3a 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -228,6 +228,11 @@ public:
int n = cmdObj.getIntField("n");
bool inc = cmdObj.getBoolField("inc"); // inclusive range?
+ if (n <= 0) {
+ return appendCommandStatus(result,
+ {ErrorCodes::BadValue, "n must be a positive integer"});
+ }
+
OldClientWriteContext ctx(txn, fullNs);
Collection* collection = ctx.getCollection();