summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-04-23 21:19:54 +0000
committerrubidium <rubidium@openttd.org>2014-04-23 21:19:54 +0000
commit160ad31028c6d089ee9bc69581c9a25da00912aa (patch)
treefdc5824209073955caac85a67a9f791dafd8937e /src/network
parenta5274117bdc323aedc95dbecea6014a308b9a9a0 (diff)
downloadopenttd-160ad31028c6d089ee9bc69581c9a25da00912aa.tar.xz
(svn r26488) -Codechange: perform the appropriate length checks when getting a client name
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_client.cpp2
-rw-r--r--src/network/network_internal.h2
-rw-r--r--src/network/network_server.cpp10
3 files changed, 7 insertions, 7 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 8098c00c2..326af65d7 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -1231,7 +1231,7 @@ void NetworkUpdateClientName()
if (!_network_server) {
MyClient::SendSetName(_settings_client.network.client_name);
} else {
- if (NetworkFindName(_settings_client.network.client_name)) {
+ if (NetworkFindName(_settings_client.network.client_name, lastof(_settings_client.network.client_name))) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, _settings_client.network.client_name);
strecpy(ci->client_name, _settings_client.network.client_name, lastof(ci->client_name));
NetworkUpdateClientInfo(CLIENT_ID_SERVER);
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index 60862dd7f..ed9a8de6f 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -168,7 +168,7 @@ void NetworkError(StringID error_string);
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
uint NetworkCalculateLag(const NetworkClientSocket *cs);
StringID GetNetworkErrorMsg(NetworkErrorCode err);
-bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
+bool NetworkFindName(char *new_name, const char *last);
const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed);
#endif /* ENABLE_NETWORK */
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 8396585d2..187dfdef8 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -941,7 +941,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
/* We need a valid name.. make it Player */
if (StrEmpty(name)) strecpy(name, "Player", lastof(name));
- if (!NetworkFindName(name)) { // Change name if duplicate
+ if (!NetworkFindName(name, lastof(name))) { // Change name if duplicate
/* We could not create a name for this client */
return this->SendError(NETWORK_ERROR_NAME_IN_USE);
}
@@ -1443,7 +1443,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet
if (ci != NULL) {
/* Display change */
- if (NetworkFindName(client_name)) {
+ if (NetworkFindName(client_name, lastof(client_name))) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, client_name);
strecpy(ci->client_name, client_name, lastof(ci->client_name));
NetworkUpdateClientInfo(ci->client_id);
@@ -1701,15 +1701,15 @@ static void NetworkAutoCleanCompanies()
/**
* Check whether a name is unique, and otherwise try to make it unique.
* @param new_name The name to check/modify.
+ * @param last The last writeable element of the buffer.
* @return True if an unique name was achieved.
*/
-bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH])
+bool NetworkFindName(char *new_name, const char *last)
{
bool found_name = false;
uint number = 0;
char original_name[NETWORK_CLIENT_NAME_LENGTH];
- /* We use NETWORK_CLIENT_NAME_LENGTH in here, because new_name is really a pointer */
strecpy(original_name, new_name, lastof(original_name));
while (!found_name) {
@@ -1734,7 +1734,7 @@ bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH])
/* Something's really wrong when there're more names than clients */
if (number++ > MAX_CLIENTS) break;
- snprintf(new_name, NETWORK_CLIENT_NAME_LENGTH, "%s #%d", original_name, number);
+ seprintf(new_name, last, "%s #%d", original_name, number);
}
}