Skip to content

Commit

Permalink
util: avoid underflow in SplitHostPort
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Mar 5, 2024
1 parent 6e92287 commit 2c233c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/strencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void SplitHostPort(std::string in, int &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)) {
int32_t n;
if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) {
Expand Down

0 comments on commit 2c233c1

Please sign in to comment.