Skip to content

Commit 4600132

Browse files
committed
rpc: Validate -rpcauth arguments
1 parent d37c813 commit 4600132

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/httprpc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,14 @@ static bool InitRPCAuthentication()
253253
if (gArgs.GetArg("-rpcauth","") != "")
254254
{
255255
LogPrintf("Using rpcauth authentication.\n");
256-
for (std::string rpcauth : gArgs.GetArgs("-rpcauth")) {
256+
for (const std::string& rpcauth : gArgs.GetArgs("-rpcauth")) {
257257
std::vector<std::string> fields;
258258
boost::split(fields, rpcauth, boost::is_any_of(":$"));
259259
if (fields.size() == 3) {
260260
g_rpcauth.push_back(fields);
261+
} else {
262+
LogPrintf("Invalid -rpcauth argument.\n");
263+
return false;
261264
}
262265
}
263266
}

test/functional/rpc_users.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,18 @@ def run_test(self):
9999

100100
self.test_auth(self.nodes[1], self.rpcuser, self.rpcpassword)
101101

102-
self.log.info('Check that failure to write cookie file will abort the node gracefully')
102+
init_error = 'Error: Unable to start HTTP server. See debug log for details.'
103+
104+
self.log.info('Check -rpcauth are validated')
105+
# Empty -rpcauth= are ignored
106+
self.restart_node(0, extra_args=['-rpcauth='])
103107
self.stop_node(0)
108+
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo'])
109+
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo:bar'])
110+
111+
self.log.info('Check that failure to write cookie file will abort the node gracefully')
104112
cookie_file = os.path.join(get_datadir_path(self.options.tmpdir, 0), self.chain, '.cookie.tmp')
105113
os.mkdir(cookie_file)
106-
init_error = 'Error: Unable to start HTTP server. See debug log for details.'
107114
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)
108115

109116

0 commit comments

Comments
 (0)