From 97b072a9f6b568f3b669486fced018aa833751d1 Mon Sep 17 00:00:00 2001 From: LevShisterov Date: Tue, 20 Dec 2016 02:06:39 +0500 Subject: [PATCH] PVS/PAS buffer overrun fix (#282) Fix buffer overrun in adding to fat PVS/PAS. --- rehlds/engine/sv_main.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 9e5df0a..213f50c 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -2078,9 +2078,9 @@ void SV_ReplaceSpecialCharactersInName(char *newname, const char *oldname) for (const char *s = oldname; *s != '\0' && remainChars; s++) { if (*s == '#' || - *s == '%' || - *s == '&' || - (n && newname[n-1] == '+' && (signed char)*s > 0 && isalnum(*s))) + *s == '%' || + *s == '&' || + (n && newname[n-1] == '+' && (signed char)*s > 0 && isalnum(*s))) { if (remainChars < 3) break; @@ -3979,7 +3979,11 @@ void SV_AddToFatPVS(vec_t *org, mnode_t *node) unsigned char* EXT_FUNC SV_FatPVS(float *org) { +#ifdef REHLDS_FIXES + fatbytes = gPVSRowBytes; +#else // REHLDS_FIXES fatbytes = (g_psv.worldmodel->numleafs + 31) >> 3; +#endif // REHLDS_FIXES Q_memset(fatpvs, 0, fatbytes); SV_AddToFatPVS(org, g_psv.worldmodel->nodes); return fatpvs; @@ -4030,7 +4034,11 @@ void SV_AddToFatPAS(vec_t *org, mnode_t *node) unsigned char* EXT_FUNC SV_FatPAS(float *org) { +#ifdef REHLDS_FIXES + fatpasbytes = gPVSRowBytes; +#else // REHLDS_FIXES fatpasbytes = (g_psv.worldmodel->numleafs + 31) >> 3; +#endif // REHLDS_FIXES Q_memset(fatpas, 0, fatpasbytes); SV_AddToFatPAS(org, g_psv.worldmodel->nodes); return fatpas; @@ -6093,7 +6101,7 @@ void FilterToString(const ipfilter_t &f, char *s) bool IsFilterIncludesAnotherFilter(const ipfilter_t &f, const ipfilter_t &f2) { return f2.mask >= f.mask - && (f2.compare.u32 & f.mask) == f.compare.u32; + && (f2.compare.u32 & f.mask) == f.compare.u32; } qboolean StringToFilter(const char *s, ipfilter_t *f) @@ -6775,10 +6783,10 @@ void SV_AddIP_f(void) if (Cmd_Argc() != 3) { #ifdef REHLDS_FIXES - Con_Printf("Usage: addip \n\ - addip \n\ -Use 0 minutes for permanent\n\ -ipaddress A.B.C.D/24 is equivalent to A.B.C.0 and A.B.C\n"); + Con_Printf("Usage: addip \n" + " addip \n" + "Use 0 minutes for permanent\n" + "ipaddress A.B.C.D/24 is equivalent to A.B.C.0 and A.B.C\n"); #else // REHLDS_FIXES Con_Printf("Usage: addip \nUse 0 minutes for permanent\n"); #endif // REHLDS_FIXES @@ -6876,9 +6884,9 @@ void SV_RemoveIP_f(void) int argCount = Cmd_Argc(); if (argCount != 2 && argCount != 3) { - Con_Printf("Usage: removeip {removeAll}\n\ - removeip {removeAll}\n\ -Use removeAll to delete all ip filters which ipaddress or ipaddress/CIDR includes\n"); + Con_Printf("Usage: removeip {removeAll}\n" + "removeip {removeAll}\n" + "Use removeAll to delete all ip filters which ipaddress or ipaddress/CIDR includes\n"); return; } @@ -6889,10 +6897,10 @@ Use removeAll to delete all ip filters which ipaddress or ipaddress/CIDR include if (!StringToFilter(Cmd_Argv(1), &f)) { #ifdef REHLDS_FIXES - Con_Printf("Invalid IP address\n\ -Usage: removeip {removeAll}\n\ - removeip {removeAll}\n\ -Use removeAll to delete all ip filters which ipaddress or ipaddress/CIDR includes\n"); + Con_Printf("Invalid IP address\n" + "Usage: removeip {removeAll}\n" + " removeip {removeAll}\n" + "Use removeAll to delete all ip filters which ipaddress or ipaddress/CIDR includes\n"); #endif // REHLDS_FIXES return;