From ebe32ad9129bb5846433366509728fb594f3be62 Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Sun, 2 May 2021 09:15:12 +0200 Subject: Codechange: [Network] Use std::string for the internal handling of admin/rcon passwords --- src/network/network_admin.cpp | 3 +-- src/network/network_client.cpp | 2 +- src/network/network_client.h | 2 +- src/network/network_server.cpp | 5 ++--- 4 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 057ce32c0..dfe09344a 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -664,8 +664,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p) { if (this->status != ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); - char password[NETWORK_PASSWORD_LENGTH]; - p->Recv_string(password, sizeof(password)); + std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH); if (_settings_client.network.admin_password.empty() || _settings_client.network.admin_password.compare(password) != 0) { diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 4740849a0..7e2c7bb23 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -516,7 +516,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit() * @param pass The password for the remote command. * @param command The actual command. */ -NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const char *pass, const char *command) +NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const std::string &pass, const char *command) { Packet *p = new Packet(PACKET_CLIENT_RCON); p->Send_string(pass); diff --git a/src/network/network_client.h b/src/network/network_client.h index baf4f5996..7d0d22810 100644 --- a/src/network/network_client.h +++ b/src/network/network_client.h @@ -96,7 +96,7 @@ public: static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data); static NetworkRecvStatus SendSetPassword(const std::string &password); static NetworkRecvStatus SendSetName(const char *name); - static NetworkRecvStatus SendRCon(const char *password, const char *command); + static NetworkRecvStatus SendRCon(const std::string &password, const char *command); static NetworkRecvStatus SendMove(CompanyID company, const std::string &password); static bool IsConnected(); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 314407348..7b77c76c4 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1431,15 +1431,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p) { if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); - char pass[NETWORK_PASSWORD_LENGTH]; char command[NETWORK_RCONCOMMAND_LENGTH]; if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY; - p->Recv_string(pass, sizeof(pass)); + std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH); p->Recv_string(command, sizeof(command)); - if (_settings_client.network.rcon_password.compare(pass) != 0) { + if (_settings_client.network.rcon_password.compare(password) != 0) { DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id); return NETWORK_RECV_STATUS_OKAY; } -- cgit v1.2.3-70-g09d2