summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/server22767.js
blob: 74efd3eade4487ad5824a45b6b9f00a8208aa1ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// test that the mongos doesn't segfault when it receives malformed BSON
var st = new ShardingTest({shards: 1});
var testDB = st.getDB('test');
testDB.test.insert({a: 1});

try {
    testDB.test.find({key: {$regex: 'abcd\0xyz'}}).explain();
} catch (e) {
    /*
     * if the mongos segfaults, the error is the msg:
     * "Error: error doing query: failed: network error while attempting to run command 'explain' on
     *host '127.0.0.1:20014'"
     *
     * if the mongos doesn't segfault, the error is the object:
     * "Error: explain failed: {
     *   "code" : 22,
     *   "ok" : 0,
     *   "errmsg" : "bson length doesn't match what we found in object with unknown _id"
     * }"
     */
    assert.eq(22, e.code);
}