Skip to content

Commit dcfef27

Browse files
committed
cli: Reject arguments to -getinfo
Currently it's possible to accidentally type e.g. bitcoin-cli -getinfo getbalance and get an answer which can be confusing; the trialing arguments are just ignored. To avoid this, throw an error if the user provides arguments to `-getinfo`.
1 parent 1f7695b commit dcfef27

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: src/bitcoin-cli.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ class GetinfoRequestHandler: public BaseRequestHandler
213213
/** Create a simulated `getinfo` request. */
214214
UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
215215
{
216+
if (!args.empty()) {
217+
throw std::runtime_error("-getinfo takes no arguments");
218+
}
216219
UniValue result(UniValue::VARR);
217220
result.push_back(JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO));
218221
result.push_back(JSONRPCRequestObj("getblockchaininfo", NullUniValue, ID_BLOCKCHAININFO));

Diff for: test/functional/bitcoin_cli.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ def run_test(self):
3535
assert_equal(["foo", "bar"], self.nodes[0].cli('-rpcuser=%s' % user, '-stdin', '-stdinrpcpass', input=password + "\nfoo\nbar").echo())
3636
assert_raises_process_error(1, "incorrect rpcuser or rpcpassword", self.nodes[0].cli('-rpcuser=%s' % user, '-stdin', '-stdinrpcpass', input="foo").echo)
3737

38+
self.log.info("Make sure that -getinfo with arguments fails")
39+
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
40+
3841
self.log.info("Compare responses from `bitcoin-cli -getinfo` and the RPCs data is retrieved from.")
39-
cli_get_info = self.nodes[0].cli('-getinfo').help()
42+
cli_get_info = self.nodes[0].cli().send_cli('-getinfo')
4043
wallet_info = self.nodes[0].getwalletinfo()
4144
network_info = self.nodes[0].getnetworkinfo()
4245
blockchain_info = self.nodes[0].getblockchaininfo()

0 commit comments

Comments
 (0)