summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-12-15 20:08:01 +0000
committerdarkvater <darkvater@openttd.org>2004-12-15 20:08:01 +0000
commitd867a845fd50dc2cb47223ff8ba16ae0e9db506b (patch)
tree0a044d0b2ed3a4384ca37da5d49b919c1e01ef40
parentd7d3ff484940b9c6ceee8f16ace7bc6bd3624bbb (diff)
downloadopenttd-d867a845fd50dc2cb47223ff8ba16ae0e9db506b.tar.xz
(svn r1104) -Fix: nasty server crash buffer overflow problem when using release build. Big thanks to Truelight for the guidance in fixing this very annoying bug!
-VS.NET now treats warnings as errors too in the release build.
-rw-r--r--network_server.c18
-rw-r--r--ttd.vcproj2
2 files changed, 9 insertions, 11 deletions
diff --git a/network_server.c b/network_server.c
index f0a8c916f..32410cafa 100644
--- a/network_server.c
+++ b/network_server.c
@@ -1186,24 +1186,20 @@ void NetworkPopulateCompanyInfo(void)
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
// Register local player (if not dedicated)
- if (ci != NULL && _local_player < MAX_PLAYERS) {
- snprintf(_network_player_info[ci->client_playas-1].players, sizeof(_network_player_info[ci->client_playas-1].players), "%s", ci->client_name);
- }
+ if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS)
+ ttd_strlcpy(_network_player_info[ci->client_playas-1].players, ci->client_name, sizeof(_network_player_info[ci->client_playas-1].players));
FOR_ALL_CLIENTS(cs) {
char client_name[NETWORK_NAME_LENGTH];
- char temp[NETWORK_PLAYERS_LENGTH];
NetworkGetClientName(client_name, sizeof(client_name), cs);
ci = DEREF_CLIENT_INFO(cs);
- if (ci != NULL && ci->client_playas <= MAX_PLAYERS) {
- if (_network_player_info[ci->client_playas-1].players[0] == '\0')
- snprintf(_network_player_info[ci->client_playas-1].players, sizeof(_network_player_info[ci->client_playas-1].players), "%s", client_name);
- else {
- snprintf(temp, sizeof(temp), "%s, %s", _network_player_info[ci->client_playas-1].players, client_name);
- snprintf(_network_player_info[ci->client_playas-1].players, sizeof(_network_player_info[ci->client_playas-1].players), "%s", temp);
- }
+ if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) {
+ if (strlen(_network_player_info[ci->client_playas-1].players) != 0)
+ strncat(_network_player_info[ci->client_playas-1].players, ", ", sizeof(_network_player_info[ci->client_playas-1].players));
+
+ strncat(_network_player_info[ci->client_playas-1].players, client_name, sizeof(_network_player_info[ci->client_playas-1].players));
}
}
}
diff --git a/ttd.vcproj b/ttd.vcproj
index 3ffd06557..e1feecd02 100644
--- a/ttd.vcproj
+++ b/ttd.vcproj
@@ -45,6 +45,7 @@
ProgramDataBaseFileName=".\Release/"
BrowseInformation="1"
WarningLevel="3"
+ WarnAsError="TRUE"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"
CompileAs="1"/>
@@ -118,6 +119,7 @@
ProgramDataBaseFileName=".\Checked/"
BrowseInformation="1"
WarningLevel="3"
+ WarnAsError="TRUE"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"
CallingConvention="1"