Skip to content

Commit 243a9c3

Browse files
committed
Merge bitcoin/bitcoin#24297: Fix unintended unsigned integer overflow in strencodings
fac9fe5 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 fac9fe5 shaavan: Code Review ACK fac9fe5 Tree-SHA512: e71c21a0b617abf241e561ce6b90b963e2d5e2f77bd9547ce47209a1a94b454384391f86ef5d35fedd4f4df19add3896bb3d61fed396ebba8e864e3eeb75ed59
2 parents 8796c2f + fac9fe5 commit 243a9c3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/util/strencodings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut)
113113
// if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
114114
bool fHaveColon = colon != in.npos;
115115
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
116-
bool fMultiColon = fHaveColon && (in.find_last_of(':', colon - 1) != in.npos);
116+
bool fMultiColon{fHaveColon && colon != 0 && (in.find_last_of(':', colon - 1) != in.npos)};
117117
if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
118118
uint16_t n;
119119
if (ParseUInt16(in.substr(colon + 1), &n)) {

0 commit comments

Comments
 (0)