aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-02-09 13:26:38 +0100
committerMarcoFalke <falke.marco@gmail.com>2022-02-09 13:24:55 +0100
commitfac9fe5d051264fcd16e8e36d30f28c05c999837 (patch)
tree03631d8eac5f0ad5bb3a163619e3603d4ab52581
parent8ac79973f8e923e9f1f560f4909b912ccea34035 (diff)
downloadbitcoin-fac9fe5d051264fcd16e8e36d30f28c05c999837.tar.xz
Fix unintended unsigned integer overflow in strencodings
-rw-r--r--src/util/strencodings.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index a386f2b7b3..a18eeba563 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -113,7 +113,7 @@ void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut)
// if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
bool fHaveColon = colon != in.npos;
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 && (in.find_last_of(':', colon - 1) != in.npos);
+ 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)) {