diff --git a/src/groups/mwc/mwcio/mwcio_channel.cpp b/src/groups/mwc/mwcio/mwcio_channel.cpp index 91ae5bbc8c..4146190428 100644 --- a/src/groups/mwc/mwcio/mwcio_channel.cpp +++ b/src/groups/mwc/mwcio/mwcio_channel.cpp @@ -63,7 +63,7 @@ bool ChannelWatermarkType::fromAscii(ChannelWatermarkType::Enum* out, #define CHECKVALUE(M) \ if (bdlb::String::areEqualCaseless(toAscii(ChannelWatermarkType::e_##M), \ str.data(), \ - str.length())) { \ + static_cast(str.length()))) { \ *out = ChannelWatermarkType::e_##M; \ return true; \ } diff --git a/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp b/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp index f538d4a32c..c1ab1db865 100644 --- a/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp +++ b/src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp @@ -90,11 +90,13 @@ bool TCPEndpoint::fromUri(const bsl::string& uri) } // Extract the port part: i.e. after the last ':' - d_port = bsl::strtol(uri.c_str() + colon + 1, 0, 10); + const long port = bsl::strtol(uri.c_str() + colon + 1, 0, 10); - if (d_port == 0) { + // For simplicity, do not accept ambiguous `port` value 0 + if (port <= 0 || port > 65535) { return false; // RETURN } + d_port = static_cast(port); // Extract the host part: i.e. between '/' and ':' d_host.assign(uri, k_SCHEME_LEN, colon - k_SCHEME_LEN); @@ -111,7 +113,18 @@ void TCPEndpoint::fromUriRaw(const bsl::string& uri) const size_t separator = uri.find_last_of(':'); - d_port = bsl::strtol(uri.c_str() + separator + 1, 0, 10); + if (separator == bsl::string::npos) { + return; // RETURN + } + + const long port = bsl::strtol(uri.c_str() + separator + 1, 0, 10); + + // For simplicity, do not accept ambiguous `port` value 0 + if (port <= 0 || port > 65535) { + return; // RETURN + } + + d_port = static_cast(port); d_host.assign(uri, k_SCHEME_LEN, separator - k_SCHEME_LEN); }