From 9dae9ed797de8f99922945132f8a47bd4f5fada4 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 18 Nov 2017 12:05:27 +0100 Subject: [PATCH] Merge #11710: cli: Reject arguments to -getinfo Summary: dcfef27 cli: Reject arguments to -getinfo (Wladimir J. van der Laan) Pull request description: Currently it's possible to accidentally type e.g. bitcoin-cli -getinfo getbalance and get an answer which can be confusing; the trailing arguments are just ignored. To avoid this, throw an error if the user provides arguments to `-getinfo`. Tree-SHA512: 3603e8fa852b884d1dd3b7462db40b092fe8b3390fd4384b4ee330315d797aff711e9f62990012fd4b5a55c8678734ba8497a5488a09ee6b65cf8a99017d6eb4 Backport of Core PR11710 https://github.com/bitcoin/bitcoin/pull/11710/ Please note, this is `./bitcoin-cli -getinfo`, NOT the deprecated/removed RPC call. Test Plan: make check test_runner.py Reviewers: jasonbcox, deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc, markblundeberg Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, markblundeberg Subscribers: markblundeberg Differential Revision: https://reviews.bitcoinabc.org/D3229 --- doc/release-notes.md | 1 + src/bitcoin-cli.cpp | 3 +++ test/functional/interface_bitcoin_cli.py | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/release-notes.md b/doc/release-notes.md index 05c0af90a6..1f82df3a6f 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -4,3 +4,4 @@ Bitcoin ABC version 0.19.8 is now available from: This release includes the following features and fixes: - Remove `getinfo` RPC in favor of `getblockchaininfo`, `getnetworkinfo` and `getwalletinfo`. + - `./bitcoin-cli -getinfo` will now throw a runtime error if there are any extra arguments after it. diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 594f84444e..2a25d8f644 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -257,6 +257,9 @@ class GetinfoRequestHandler : public BaseRequestHandler { /** Create a simulated `getinfo` request. */ UniValue PrepareRequest(const std::string &method, const std::vector &args) override { + if (!args.empty()) { + throw std::runtime_error("-getinfo takes no arguments"); + } UniValue result(UniValue::VARR); result.push_back( JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO)); diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py index 713b94b701..c9f0269408 100755 --- a/test/functional/interface_bitcoin_cli.py +++ b/test/functional/interface_bitcoin_cli.py @@ -46,9 +46,13 @@ def run_test(self): assert_raises_process_error(1, "incorrect rpcuser or rpcpassword", self.nodes[0].cli( '-rpcuser={}'.format(user), '-stdin', '-stdinrpcpass', input="foo").echo) + self.log.info("Make sure that -getinfo with arguments fails") + assert_raises_process_error( + 1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help) + self.log.info( "Compare responses from `bitcoin-cli -getinfo` and the RPCs data is retrieved from.") - cli_get_info = self.nodes[0].cli('-getinfo').help() + cli_get_info = self.nodes[0].cli().send_cli('-getinfo') wallet_info = self.nodes[0].getwalletinfo() network_info = self.nodes[0].getnetworkinfo() blockchain_info = self.nodes[0].getblockchaininfo()