From 47bbacc7bb133a2b59c4b3bbf81596579c9beb8a Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sat, 2 May 2009 00:58:21 +0000 Subject: [PATCH] Bugfix: NUL terminate the MOTD string buffer If registering with the lobby server failed once, we don't want part of the failure message to be kept at the end of the MOTD string. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7270 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/netplay/netplay.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/netplay/netplay.c b/lib/netplay/netplay.c index aaada6760..26502420b 100644 --- a/lib/netplay/netplay.c +++ b/lib/netplay/netplay.c @@ -1830,12 +1830,14 @@ static void NETregisterServer(int state) } if (SDLNet_SocketReady(rs_socket)) // true on activity { - result = SDLNet_TCP_Recv(rs_socket, NetPlay.MOTDbuffer, sizeof(NetPlay.MOTDbuffer)); + result = SDLNet_TCP_Recv(rs_socket, NetPlay.MOTDbuffer, sizeof(NetPlay.MOTDbuffer) - 1); if (result <= 0) { debug(LOG_NET, "Warning, MOTD TCP_Recv failed. result = %d, error %s", result, SDLNet_GetError()); sstrcpy(NetPlay.MOTDbuffer, "MOTD communication error with lobby server, TCP_Recv failed!"); } + // Make sure to NUL terminate the MOTD string + NetPlay.MOTDbuffer[result] = '\0'; debug(LOG_NET, "MOTD is [%s]", NetPlay.MOTDbuffer); } else