From 5453e66fd91c303d04004d861ecad183ff177823 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 19 Dec 2019 18:00:04 -0500 Subject: [PATCH 01/15] Fix nonsensical -noseednode behavior Treat specifying -noseednode the same as not specifying any -seednode value, instead of enabling the seed node timeout and log messages, and waiting longer to add other seeds. --- src/net.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c722ddfcb5f..9d42bafb559 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2246,7 +2246,7 @@ void CConnman::ThreadDNSAddressSeed() { int outbound_connection_count = 0; - if (gArgs.IsArgSet("-seednode")) { + if (!gArgs.GetArgs("-seednode").empty()) { auto start = NodeClock::now(); constexpr std::chrono::seconds SEEDNODE_TIMEOUT = 30s; LogPrintf("-seednode enabled. Trying the provided seeds for %d seconds before defaulting to the dnsseeds.\n", SEEDNODE_TIMEOUT.count()); @@ -2549,7 +2549,7 @@ void CConnman::ThreadOpenConnections(const std::vector connect, Spa auto next_extra_network_peer{start + rng.rand_exp_duration(EXTRA_NETWORK_PEER_INTERVAL)}; const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED); bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS); - const bool use_seednodes{gArgs.IsArgSet("-seednode")}; + const bool use_seednodes{!gArgs.GetArgs("-seednode").empty()}; auto seed_node_timer = NodeClock::now(); bool add_addr_fetch{addrman.Size() == 0 && !seed_nodes.empty()}; From 40c4899bc209921fb4bde02840359c3253663766 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 19 Dec 2019 18:00:04 -0500 Subject: [PATCH 02/15] Fix nonsensical -nobind and -nowhitebind behavior Treat specifying -nobind and -nowhitebind the same as not specifying -bind and -whitebind values instead of causing them to soft-set -listen=1. --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index d46318fd45e..5d37a349c82 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -716,11 +716,11 @@ void InitParameterInteraction(ArgsManager& args) { // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified - if (args.IsArgSet("-bind")) { + if (!args.GetArgs("-bind").empty()) { if (args.SoftSetBoolArg("-listen", true)) LogInfo("parameter interaction: -bind set -> setting -listen=1\n"); } - if (args.IsArgSet("-whitebind")) { + if (!args.GetArgs("-whitebind").empty()) { if (args.SoftSetBoolArg("-listen", true)) LogInfo("parameter interaction: -whitebind set -> setting -listen=1\n"); } From e03409c70f7472d39e45d189df6c0cf6b676b761 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 19 Dec 2019 18:00:04 -0500 Subject: [PATCH 03/15] Fix nonsensical -norpcbind and -norpcallowip behavior Treat specifying -norpcbind and -norpcallowip the same as not specifying -rpcbind or -rpcallowip, instead of failing to bind to localhost and failing to show warnings. Also add code comment to clarify what intent of existing code is. --- src/httpserver.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 88e640c377c..bd2dec19b97 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -362,16 +362,20 @@ static bool HTTPBindAddresses(struct evhttp* http) std::vector> endpoints; // Determine what addresses to bind to - if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs + // To prevent misconfiguration and accidental exposure of the RPC + // interface, require -rpcallowip and -rpcbind to both be specified + // together. If either is missing, ignore both values, bind to localhost + // instead, and log warnings. + if (gArgs.GetArgs("-rpcallowip").empty() || gArgs.GetArgs("-rpcbind").empty()) { // Default to loopback if not allowing external IPs endpoints.emplace_back("::1", http_port); endpoints.emplace_back("127.0.0.1", http_port); - if (gArgs.IsArgSet("-rpcallowip")) { + if (!gArgs.GetArgs("-rpcallowip").empty()) { LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n"); } - if (gArgs.IsArgSet("-rpcbind")) { + if (!gArgs.GetArgs("-rpcbind").empty()) { LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); } - } else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address + } else { // Specific bind addresses for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) { uint16_t port{http_port}; std::string host; From 6768389917a8d744f1b1ada4556d3d4fe63c310e Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 19 Dec 2019 18:00:04 -0500 Subject: [PATCH 04/15] Fix nonsensical -norpcwhitelist behavior Treat specifying -norpcwhitelist the same as not specifying -rpcwhitelist, instead of behaving almost the same but flipping the default -rpcwhitelistdefault value. This is confusing because before this change if -norpcwhitelist was specified it would block users from calling any RPC methods. --- src/httprpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 5d906ffa0c2..57893702b8b 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -334,7 +334,7 @@ static bool InitRPCAuthentication() } } - g_rpc_whitelist_default = gArgs.GetBoolArg("-rpcwhitelistdefault", gArgs.IsArgSet("-rpcwhitelist")); + g_rpc_whitelist_default = gArgs.GetBoolArg("-rpcwhitelistdefault", !gArgs.GetArgs("-rpcwhitelist").empty()); for (const std::string& strRPCWhitelist : gArgs.GetArgs("-rpcwhitelist")) { auto pos = strRPCWhitelist.find(':'); std::string strUser = strRPCWhitelist.substr(0, pos); From b6ab3508064cd3135e1a356c884ae1269cda5250 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 19 Dec 2019 18:00:04 -0500 Subject: [PATCH 05/15] Fix nonsensical -notest behavior Treat specifying -notest exactly the same as not specifying any -test value, instead of complaining that it must be used with -regtest. --- src/init.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 5d37a349c82..771efc64918 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1044,12 +1044,12 @@ bool AppInitParameterInteraction(const ArgsManager& args) if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS)) g_local_services = ServiceFlags(g_local_services | NODE_BLOOM); - if (args.IsArgSet("-test")) { + const std::vector test_options = args.GetArgs("-test"); + if (!test_options.empty()) { if (chainparams.GetChainType() != ChainType::REGTEST) { return InitError(Untranslated("-test=