diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2020-11-23 12:00:50 +0000 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2020-11-23 21:02:54 +0000 |
commit | 46001323b1f4a57d8d6805f1bc39a5b8d401f0c5 (patch) | |
tree | dcf642362f9b159faccf40c62cb07a31390c64cc | |
parent | d37c813a43166f559a4e2d1c22e7243f70301291 (diff) |
rpc: Validate -rpcauth arguments
-rw-r--r-- | src/httprpc.cpp | 5 | ||||
-rwxr-xr-x | test/functional/rpc_users.py | 11 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/httprpc.cpp b/src/httprpc.cpp index f3b2619dbd..cb8b220895 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -253,11 +253,14 @@ static bool InitRPCAuthentication() if (gArgs.GetArg("-rpcauth","") != "") { LogPrintf("Using rpcauth authentication.\n"); - for (std::string rpcauth : gArgs.GetArgs("-rpcauth")) { + for (const std::string& rpcauth : gArgs.GetArgs("-rpcauth")) { std::vector<std::string> fields; boost::split(fields, rpcauth, boost::is_any_of(":$")); if (fields.size() == 3) { g_rpcauth.push_back(fields); + } else { + LogPrintf("Invalid -rpcauth argument.\n"); + return false; } } } diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py index daf02fc4f3..108af2cac8 100755 --- a/test/functional/rpc_users.py +++ b/test/functional/rpc_users.py @@ -99,11 +99,18 @@ class HTTPBasicsTest(BitcoinTestFramework): self.test_auth(self.nodes[1], self.rpcuser, self.rpcpassword) - self.log.info('Check that failure to write cookie file will abort the node gracefully') + init_error = 'Error: Unable to start HTTP server. See debug log for details.' + + self.log.info('Check -rpcauth are validated') + # Empty -rpcauth= are ignored + self.restart_node(0, extra_args=['-rpcauth=']) self.stop_node(0) + self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo']) + self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo:bar']) + + self.log.info('Check that failure to write cookie file will abort the node gracefully') cookie_file = os.path.join(get_datadir_path(self.options.tmpdir, 0), self.chain, '.cookie.tmp') os.mkdir(cookie_file) - init_error = 'Error: Unable to start HTTP server. See debug log for details.' self.nodes[0].assert_start_raises_init_error(expected_msg=init_error) |