diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 8b258f5fa..53aec416d 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -115,6 +115,10 @@ int main(int argc, const char* argv[]) { std::string remote_host_ips; uint16_t remote_port = absl::GetFlag(FLAGS_server_port); + if (remote_port == 0u) { + LOG(WARNING) << "Invalid server port: " << remote_port; + return -1; + } auto results = ResolveAddress(remote_host_name, remote_port); if (results.empty()) { diff --git a/src/config/config.cpp b/src/config/config.cpp index fc9cfebca..8fee07d4c 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -139,7 +139,7 @@ std::string ReadConfigFromArgument(std::string_view server_host, } auto server_port = StringToIntegerU(_server_port); - if (!server_port.has_value() || server_port.value() > 65535u) { + if (!server_port.has_value() || server_port.value() == 0u || server_port.value() > 65535u) { err_msg << ",Invalid Server Port: " << _server_port; } @@ -218,7 +218,7 @@ std::string ReadConfigFromArgument(std::string_view server_host, } auto server_port = StringToIntegerU(_server_port); - if (!server_port.has_value() || server_port.value() > 65535u) { + if (!server_port.has_value() || server_port.value() == 0u || server_port.value() > 65535u) { err_msg << ",Invalid Server Port: " << _server_port; } diff --git a/src/server/server.cpp b/src/server/server.cpp index 5d79dbe03..99b5a1392 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -120,6 +120,10 @@ int main(int argc, const char* argv[]) { std::string host_name = absl::GetFlag(FLAGS_server_host); std::string host_sni = host_name; uint16_t port = absl::GetFlag(FLAGS_server_port); + if (port == 0u) { + LOG(WARNING) << "Invalid server port: " << port; + return -1; + } asio::error_code ec; auto addr = asio::ip::make_address(host_name.c_str(), ec);