diff options
author | Robert Guo <robert.guo@10gen.com> | 2015-11-11 18:54:35 -0500 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2016-01-28 18:47:31 -0500 |
commit | f2a67700a3cfd9e401feb4a17931ea3209f10e4b (patch) | |
tree | 3a779280f0776e685f52e8eb7d9b7341cd8d8305 | |
parent | a2ad8f927f850ca727df7992c4ca57f680daf28d (diff) | |
download | mongo-f2a67700a3cfd9e401feb4a17931ea3209f10e4b.tar.gz |
SERVER-21388 validate captrunc argument
-rw-r--r-- | jstests/noPassthroughWithMongod/capped_truncate.js | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/test_commands.cpp | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/capped_truncate.js b/jstests/noPassthroughWithMongod/capped_truncate.js index ddba2420bba..ce559919b80 100644 --- a/jstests/noPassthroughWithMongod/capped_truncate.js +++ b/jstests/noPassthroughWithMongod/capped_truncate.js @@ -11,6 +11,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 3cbc36519ba..9a2c5cec5cd 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -189,7 +189,13 @@ 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"}); + } + Client::WriteContext ctx(txn, nss.ns()); + Collection* collection = ctx.getCollection(); massert(13417, "captrunc collection not found or empty", collection); |