0
0
mirror of https://github.com/monero-project/monero synced 2025-10-06 08:42:47 +02:00

epee: only parse valid port

Reported by hacksandhops and Ada Logic.
This commit is contained in:
selsta
2025-08-25 00:53:24 +02:00
parent 4e93cdc941
commit ca484323c3

View File

@@ -93,6 +93,12 @@ namespace net_utils
return true; return true;
} }
static bool parse_port(const std::string& port_str, uint64_t& out_port)
{
out_port = 0;
return boost::conversion::try_lexical_convert(port_str, out_port) && out_port <= 65535;
}
bool parse_uri(const std::string uri, http::uri_content& content) bool parse_uri(const std::string uri, http::uri_content& content)
{ {
@@ -153,7 +159,8 @@ namespace net_utils
} }
if(result[6].matched) if(result[6].matched)
{ {
content.port = boost::lexical_cast<uint64_t>(result[6]); if (!parse_port(result[6].str(), content.port))
return false;
} }
if(result[7].matched) if(result[7].matched)
{ {
@@ -189,7 +196,8 @@ namespace net_utils
} }
if(result[6].matched) if(result[6].matched)
{ {
content.port = boost::lexical_cast<uint64_t>(result[6]); if (!parse_port(result[6].str(), content.port))
return false;
} }
if(result[7].matched) if(result[7].matched)
{ {