aboutsummaryrefslogtreecommitdiff
path: root/src/util/strencodings.cpp
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2022-02-10 07:17:06 +0000
committerfanquake <fanquake@gmail.com>2022-02-10 07:17:32 +0000
commit243a9c39250dee95b6fe62ac5ae2f8e3eafecf1b (patch)
tree8356c0de419f421ba0cb9e90914f1647a2ec376c /src/util/strencodings.cpp
parent8796c2f5688d87be6580e28d7f5d1a235c338e6d (diff)
parentfac9fe5d051264fcd16e8e36d30f28c05c999837 (diff)
downloadbitcoin-243a9c39250dee95b6fe62ac5ae2f8e3eafecf1b.tar.xz
Merge bitcoin/bitcoin#24297: Fix unintended unsigned integer overflow in strencodings
fac9fe5d051264fcd16e8e36d30f28c05c999837 Fix unintended unsigned integer overflow in strencodings (MarcoFalke) Pull request description: This fixes two issues for strings that start with a colon and only have one colon: * `fMultiColon` is incorrectly set to `true` * There is an unsigned integer overflow `colon - 1` (`0 - 1`) Neither issue matters, as the result is discarded. Though, it makes sense to still fix the issue for clarity and to avoid sanitizer issues in the function. ACKs for top commit: laanwj: Code review ACK fac9fe5d051264fcd16e8e36d30f28c05c999837 shaavan: Code Review ACK fac9fe5d051264fcd16e8e36d30f28c05c999837 Tree-SHA512: e71c21a0b617abf241e561ce6b90b963e2d5e2f77bd9547ce47209a1a94b454384391f86ef5d35fedd4f4df19add3896bb3d61fed396ebba8e864e3eeb75ed59
Diffstat (limited to 'src/util/strencodings.cpp')
-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 e0f0d63ff6..940fa90da2 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)) {