From fa479857ed234d54df31d33b60de14c6ffab3d6f Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 15 May 2025 21:06:48 +0200 Subject: [PATCH] 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 --- src/util/strencodings.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index fbccebad942..0c09915c8b4 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -78,10 +78,9 @@ bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut) 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 bool fMultiColon{fHaveColon && colon != 0 && (in.find_last_of(':', colon - 1) != in.npos)}; if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { - uint16_t n; - if (ParseUInt16(in.substr(colon + 1), &n)) { + if (const auto n{ToIntegral(in.substr(colon + 1))}) { in = in.substr(0, colon); - portOut = n; + portOut = *n; valid = (portOut != 0); } } else {