Skip to content

Commit d38e3ae

Browse files
committed
fix: handle invalid rpcbind port earlier
Previously, when an invalid port was specified in `-rpcbind`, the `SplitHostPort()` return value in `HTTPBindAddresses()` was ignored and attempt would be made to bind to the default rpcbind port (with the host/port treated as a host). This rearranges port checking code in `AppInitMain()` to handle the invalid port before reaching `HTTPBindAddresses()`. Also adjusts associated functional tests.
1 parent 83b67f2 commit d38e3ae

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12791279
RegisterZMQRPCCommands(tableRPC);
12801280
#endif
12811281

1282+
// Check port numbers
1283+
if (!CheckHostPortOptions(args)) return false;
1284+
12821285
/* Start the RPC server already. It will be started in "warmup" mode
12831286
* and not really process calls already (but it will signify connections
12841287
* that the server is there and will be ready later). Warmup mode will
@@ -1369,9 +1372,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13691372
validation_signals.RegisterValidationInterface(fee_estimator);
13701373
}
13711374

1372-
// Check port numbers
1373-
if (!CheckHostPortOptions(args)) return false;
1374-
13751375
for (const std::string& socket_addr : args.GetArgs("-bind")) {
13761376
std::string host_out;
13771377
uint16_t port_out{0};

test/functional/rpc_bind.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from test_framework.netutil import all_interfaces, addr_to_hex, get_bind_addrs, test_ipv6_local
88
from test_framework.test_framework import BitcoinTestFramework, SkipTest
9-
from test_framework.test_node import ErrorMatch
109
from test_framework.util import assert_equal, assert_raises_rpc_error, get_rpc_proxy, rpc_port, rpc_url
1110

1211
class RPCBindTest(BitcoinTestFramework):
@@ -55,9 +54,9 @@ def run_invalid_bind_test(self, allow_ips, addresses):
5554
base_args = ['-disablewallet', '-nolisten']
5655
if allow_ips:
5756
base_args += ['-rpcallowip=' + x for x in allow_ips]
58-
init_error = 'Error' # generic error will be adjusted in next commit
57+
init_error = 'Error: Invalid port specified in -rpcbind: '
5958
for addr in addresses:
60-
self.nodes[0].assert_start_raises_init_error(base_args + [f'-rpcbind={addr}'], init_error, ErrorMatch.PARTIAL_REGEX)
59+
self.nodes[0].assert_start_raises_init_error(base_args + [f'-rpcbind={addr}'], init_error + f"'{addr}'")
6160

6261
def run_allowip_test(self, allow_ips, rpchost, rpcport):
6362
'''

0 commit comments

Comments
 (0)