Repository navigation
Sanitizing ports of -rpcconnect and -rpcport. - #27820
Brotcrunsher wants to merge 1 commit into
Conversation
…tained malformed ports they were silently interpreted as value%0xffff. Illegal ports now lead to an error. Additionally, if rpcconnect has a port and rpcport is set, a useful warning is now printed.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
|
Concept ACK |
S3RK
left a comment
There was a problem hiding this comment.
Concept ACK.
Could you separate the PR into two commits? PR does two separate things, each of them could be placed in a separate commit:
- Handling of incorrect port values
- Warning in case both params have a port.
Also, could you add a functional test for the first? You can see similar examples in test/functional/interface_bitcoin_cli.py
| { | ||
| bool containsPort; | ||
| if (!SplitHostPort(gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host, &containsPort)) { | ||
| throw std::runtime_error(strprintf("Malformed Port in -rpcconnect: %s", gArgs.GetArg("-rpcconnect", ""))); |
There was a problem hiding this comment.
@hebasto we can reuse InvalidPortErrMsg() here, but I don't see any other users of bilingual strings. What do you recommend for bitcoin-cli?
| if (gArgs.IsArgSet("-rpcport")) { | ||
| int64_t desiredRpcPort = gArgs.GetIntArg("-rpcport", port); | ||
| if (desiredRpcPort <= 0 || desiredRpcPort > 0xFFFF) { | ||
| throw std::runtime_error(strprintf("Malformed Port in -rpcport: %lld", desiredRpcPort)); |
There was a problem hiding this comment.
nit: better to read port as a string to show it back to the user exactly as it was written.
this is how src/init.cpp does it
const std::string port = args.GetArg(port_option, "");
uint16_t n;
if (!ParseUInt16(port, &n) || n == 0) {
return InitError(InvalidPortErrMsg(port_option, port));
}| template std::optional<std::vector<uint8_t>> TryParseHex(std::string_view); | ||
|
|
||
| bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut) | ||
| bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut, bool* cPortOut) |
There was a problem hiding this comment.
Not a huge fan of this new parameter. The return value has almost exactly what we need, can we reuse it somehow?
|
Are you still working on this? |
|
Picked up in #29521. |
24bc46c cli: Add warning for duplicate port definition (tdb3) e208fb5 cli: Sanitize ports in rpcconnect and rpcport (tdb3) Pull request description: Adds invalid port detection to bitcoin-cli for -rpcconnect and -rpcport. In addition to detecting malformed/invalid ports (e.g. those outside of the 16-bit port range, not numbers, etc.), bitcoin-cli also now considers usage of port 0 to be invalid. bitcoin-cli previously considered port 0 to be valid and attempted to use it to reach bitcoind. Functional tests were added for invalid port detection as well as port prioritization. Additionally, a warning is provided when a port is specified in both -rpcconnect and -rpcport. This PR is an alternate approach to PR #27820 (e.g. SplitHostPort is unmodified). Considered an alternative to 127.0.0.1 being specified in functional tests, but at first glance, this might need an update to test_framework/util.py (e.g. rpc_url), which might be left to a future PR. ACKs for top commit: S3RK: light code review ACK 24bc46c achow101: ACK 24bc46c cbergqvist: re ACK 24bc46c Tree-SHA512: c83ab6a30a08dd1ac8b368a7dcc2b4f23170f0b61dd67ffcad7bcda05096d333bcb9821fba11018151f55b2929c0a333bfec15b8bb863d83f41fc1974c6efca5
Previously, if they contained malformed ports they were silently interpreted as value%0xffff. Illegal ports now lead to an error. Additionally, if rpcconnect has a port and rpcport is set, a useful warning is now printed.