diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2017-11-16 16:58:24 -0500 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2017-12-12 14:33:39 -0500 |
commit | b81115b17322f4afc41de1d4a06ba60f6193e544 (patch) | |
tree | 8e3e79fa42c140d5b808f351b4b84b80b6e32adf | |
parent | 4aa886846c35a8e300892fc61328c0d21182961a (diff) | |
download | mongo-b81115b17322f4afc41de1d4a06ba60f6193e544.tar.gz |
SERVER-31808 don't boost::split an empty bind_ip string
(cherry picked from commit 697db2c561f006cb9e1be9312e72c5072dd12530)
-rw-r--r-- | jstests/replsets/localhost2.js | 2 | ||||
-rw-r--r-- | jstests/replsets/localhost3.js | 13 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_commands.cpp | 4 | ||||
-rw-r--r-- | src/mongo/shell/servers.js | 2 |
4 files changed, 18 insertions, 3 deletions
diff --git a/jstests/replsets/localhost2.js b/jstests/replsets/localhost2.js index 622606a97c1..ac4dd7e0a76 100644 --- a/jstests/replsets/localhost2.js +++ b/jstests/replsets/localhost2.js @@ -12,6 +12,6 @@ tojson(resp.me) + " should not start with 127.0.0.1:"); assert(!resp.me.startsWith('0.0.0.0:'), tojson(resp.me) + " should not start with 0.0.0.0:"); assert(!resp.me.startsWith('localhost:'), - tojson(resp.me) + " should not start with 127.0.0.1:"); + tojson(resp.me) + " should not start with localhost:"); rt.stopSet(); })(); diff --git a/jstests/replsets/localhost3.js b/jstests/replsets/localhost3.js new file mode 100644 index 00000000000..ed3238a9d04 --- /dev/null +++ b/jstests/replsets/localhost3.js @@ -0,0 +1,13 @@ +// Test ReplSet default initiate with localhost-only binding + +(function() { + 'use strict'; + + // Select localhost when binding to localhost + const rt = new ReplSetTest({name: "rsLocal", nodes: 2}); + const primary = rt.startSet({bind_ip: undefined})[0]; + const db = primary.getDB('admin'); + const resp = assert.commandWorked(db.adminCommand({replSetInitiate: undefined})); + assert(resp.me.startsWith('localhost:'), tojson(resp.me) + " should start with localhost:"); + rt.stopSet(); +})(); diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp index 76873a1dd9b..3e1687500aa 100644 --- a/src/mongo/db/repl/repl_set_commands.cpp +++ b/src/mongo/db/repl/repl_set_commands.cpp @@ -256,7 +256,9 @@ HostAndPort someHostAndPortForMe() { bool localhost_only = true; std::vector<std::string> addrs; - boost::split(addrs, bind_ip, boost::is_any_of(","), boost::token_compress_on); + if (!bind_ip.empty()) { + boost::split(addrs, bind_ip, boost::is_any_of(","), boost::token_compress_on); + } for (const auto& addr : addrs) { // Get all addresses associated with each named bind host. // If we find any that are valid external identifiers, diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js index dd9c82c916c..4b4785cb43b 100644 --- a/src/mongo/shell/servers.js +++ b/src/mongo/shell/servers.js @@ -473,7 +473,7 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro opts.networkMessageCompressors = jsTestOptions().networkMessageCompressors; } - if (!opts.bind_ip) { + if (!opts.hasOwnProperty('bind_ip')) { opts.bind_ip = "0.0.0.0"; } |