@@ -90,11 +90,13 @@ bool TCPEndpoint::fromUri(const bsl::string& uri)
90
90
}
91
91
92
92
// Extract the port part: i.e. after the last ':'
93
- d_port = bsl::strtol (uri.c_str () + colon + 1 , 0 , 10 );
93
+ const long port = bsl::strtol (uri.c_str () + colon + 1 , 0 , 10 );
94
94
95
- if (d_port == 0 ) {
95
+ // For simplicity, do not accept ambiguous `port` value 0
96
+ if (port <= 0 || port > 65535 ) {
96
97
return false ; // RETURN
97
98
}
99
+ d_port = static_cast <int >(port);
98
100
99
101
// Extract the host part: i.e. between '/' and ':'
100
102
d_host.assign (uri, k_SCHEME_LEN, colon - k_SCHEME_LEN);
@@ -111,7 +113,18 @@ void TCPEndpoint::fromUriRaw(const bsl::string& uri)
111
113
112
114
const size_t separator = uri.find_last_of (' :' );
113
115
114
- d_port = bsl::strtol (uri.c_str () + separator + 1 , 0 , 10 );
116
+ if (separator == bsl::string::npos) {
117
+ return ; // RETURN
118
+ }
119
+
120
+ const long port = bsl::strtol (uri.c_str () + separator + 1 , 0 , 10 );
121
+
122
+ // For simplicity, do not accept ambiguous `port` value 0
123
+ if (port <= 0 || port > 65535 ) {
124
+ return ; // RETURN
125
+ }
126
+
127
+ d_port = static_cast <int >(port);
115
128
d_host.assign (uri, k_SCHEME_LEN, separator - k_SCHEME_LEN);
116
129
}
117
130
0 commit comments