From a4909aca6d878ce0a9ab25adbc6fd7515d7f3c0d Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 6 May 2015 01:21:52 +0300 Subject: [PATCH 1/2] Some bugfixes and improvements --- rehlds/engine/host.cpp | 6 ++++++ rehlds/engine/info.cpp | 3 ++- rehlds/engine/sv_main.cpp | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rehlds/engine/host.cpp b/rehlds/engine/host.cpp index a99ea29..7c7d2a3 100644 --- a/rehlds/engine/host.cpp +++ b/rehlds/engine/host.cpp @@ -503,6 +503,12 @@ void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...) g_psvs.stats.cumulative_sessiontime = g_psvs.stats.cumulative_sessiontime + connection_time; } +#ifdef REHLDS_FIXES + // prevent message reading after disconnect + if (cl == host_client ) + msg_readcount = net_message.cursize; +#endif // REHLDS_CHECKS + Netchan_Clear(&cl->netchan); Steam_NotifyClientDisconnect(cl); diff --git a/rehlds/engine/info.cpp b/rehlds/engine/info.cpp index 8e06f29..c523f2f 100644 --- a/rehlds/engine/info.cpp +++ b/rehlds/engine/info.cpp @@ -272,11 +272,12 @@ qboolean Info_IsKeyImportant(const char *key) return true; if (!Q_strcmp(key, "cl_lc")) return true; +#ifndef REHLDS_FIXES if (!Q_strcmp(key, "*hltv")) return true; if (!Q_strcmp(key, "*sid")) return true; - +#endif return false; } diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 4beead4..444bdf6 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -2198,7 +2198,11 @@ void SV_ConnectClient_internal(void) client_t *client; netadr_t adr; int nClientSlot; +#ifdef REHLDS_FIXES + char userinfo[MAX_INFO_STRING]; +#else char userinfo[1024]; +#endif char protinfo[1024]; char cdkey[64]; const char *s; @@ -2246,7 +2250,12 @@ void SV_ConnectClient_internal(void) } s = Cmd_Argv(4); +#ifdef REHLDS_FIXES + // truncate to 255 before sanity checks + if (Q_strlen(s) > MAX_INFO_STRING - 1 || !Info_IsValid(s)) +#else if (Q_strlen(s) > 256 || !Info_IsValid(s)) +#endif { SV_RejectConnection(&adr, "Invalid userinfo in connect command\n"); return; @@ -4442,7 +4451,14 @@ qboolean SV_SendClientDatagram(client_t *client) } else { +#ifdef REHLDS_FIXES + if (msg.cursize + client->datagram.cursize > msg.maxsize) + Con_DPrintf("Warning: Ignoring unreliable datagram for %s, would overflow on msg\n", client->name); + else + SZ_Write(&msg, client->datagram.data, client->datagram.cursize); +#else SZ_Write(&msg, client->datagram.data, client->datagram.cursize); +#endif } SZ_Clear(&client->datagram); From 49cbbeafb2e41162f92a71ef98456451a1f84139 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 6 May 2015 01:56:48 +0300 Subject: [PATCH 2/2] add comments --- rehlds/engine/host.cpp | 4 ++-- rehlds/engine/info.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rehlds/engine/host.cpp b/rehlds/engine/host.cpp index 7c7d2a3..8114beb 100644 --- a/rehlds/engine/host.cpp +++ b/rehlds/engine/host.cpp @@ -505,9 +505,9 @@ void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...) #ifdef REHLDS_FIXES // prevent message reading after disconnect - if (cl == host_client ) + if (cl == host_client) msg_readcount = net_message.cursize; -#endif // REHLDS_CHECKS +#endif // REHLDS_FIXES Netchan_Clear(&cl->netchan); diff --git a/rehlds/engine/info.cpp b/rehlds/engine/info.cpp index c523f2f..dfec4f9 100644 --- a/rehlds/engine/info.cpp +++ b/rehlds/engine/info.cpp @@ -273,11 +273,13 @@ qboolean Info_IsKeyImportant(const char *key) if (!Q_strcmp(key, "cl_lc")) return true; #ifndef REHLDS_FIXES + // keys starts from '*' already checked if (!Q_strcmp(key, "*hltv")) return true; if (!Q_strcmp(key, "*sid")) return true; #endif + return false; }