Skip to content

Commit fa47985

Browse files
author
MarcoFalke
committed
Reject + sign in SplitHostPort
It is better to reject it with an error. For example, $ bitcoin-cli -rpcconnect=127.0.0.1:+23501 -getinfo error: Invalid port provided in -rpcconnect: 127.0.0.1:+23501
1 parent fab4c29 commit fa47985

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/util/strencodings.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut)
7878
bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe
7979
bool fMultiColon{fHaveColon && colon != 0 && (in.find_last_of(':', colon - 1) != in.npos)};
8080
if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
81-
uint16_t n;
82-
if (ParseUInt16(in.substr(colon + 1), &n)) {
81+
if (const auto n{ToIntegral<uint16_t>(in.substr(colon + 1))}) {
8382
in = in.substr(0, colon);
84-
portOut = n;
83+
portOut = *n;
8584
valid = (portOut != 0);
8685
}
8786
} else {

0 commit comments

Comments
 (0)