Skip to content

Commit

Permalink
core: reject zero server port
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Apr 22, 2024
1 parent 9dba5ad commit 55d635b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 55d635b

Please sign in to comment.