Fix cases of possible buffer overrun
This commit is contained in:
+12
-3
@@ -1650,6 +1650,14 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
|
||||
|
||||
strcpy(new_pattern, "STEAM_");
|
||||
len = strlen(&info->pattern[7]);
|
||||
/* Bound the copy so the "STEAM_" prefix, the copied bytes and the
|
||||
* null terminator all fit within new_pattern. An over-long pattern
|
||||
* is simply truncated; it will not match a real client's id.
|
||||
*/
|
||||
if (len > sizeof(new_pattern) - 7)
|
||||
{
|
||||
len = sizeof(new_pattern) - 7;
|
||||
}
|
||||
for (p = 0; p < len; p++)
|
||||
{
|
||||
new_pattern[6 + p] = info->pattern[7 + p];
|
||||
@@ -1664,12 +1672,13 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
|
||||
{
|
||||
size_t p = 0;
|
||||
char c;
|
||||
while ((c = info->pattern[p + 1]) != '\0')
|
||||
/* Leave room for the null terminator; truncate over-long patterns. */
|
||||
while ((c = info->pattern[p + 1]) != '\0' && p < sizeof(new_pattern) - 1)
|
||||
{
|
||||
new_pattern[p] = (c == '_') ? ':' : c;
|
||||
new_pattern[p] = (c == '_') ? ':' : c;
|
||||
++p;
|
||||
}
|
||||
|
||||
|
||||
new_pattern[p] = '\0';
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,14 @@ inline void CellRecipientFilter::SetToReliable(bool isreliable)
|
||||
|
||||
inline void CellRecipientFilter::Initialize(cell_t *ptr, size_t count)
|
||||
{
|
||||
/* Never copy more entries than m_Players can hold. Callers derive count
|
||||
* from plugin-supplied data, which may contain duplicate client indices
|
||||
* that pass validation while exceeding the array bounds.
|
||||
*/
|
||||
if (count > (sizeof(m_Players) / sizeof(m_Players[0])))
|
||||
{
|
||||
count = sizeof(m_Players) / sizeof(m_Players[0]);
|
||||
}
|
||||
memcpy(m_Players, ptr, count * sizeof(cell_t));
|
||||
m_Size = count;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "vsound.h"
|
||||
#include <IForwardSys.h>
|
||||
#include "am-string.h"
|
||||
|
||||
SH_DECL_HOOK8_void(IVEngineServer, EmitAmbientSound, SH_NOATTRIB, 0, int, const Vector &, const char *, float, soundlevel_t, int, int, float);
|
||||
|
||||
@@ -228,7 +229,7 @@ void SoundHooks::OnEmitAmbientSound(int entindex, const Vector &pos, const char
|
||||
cell_t vec[3] = {sp_ftoc(pos.x), sp_ftoc(pos.y), sp_ftoc(pos.z)};
|
||||
cell_t res = static_cast<ResultType>(Pl_Continue);
|
||||
char buffer[PLATFORM_MAX_PATH];
|
||||
strcpy(buffer, samp);
|
||||
ke::SafeStrcpy(buffer, sizeof(buffer), samp);
|
||||
|
||||
for (iter=m_AmbientFuncs.begin(); iter!=m_AmbientFuncs.end(); iter++)
|
||||
{
|
||||
@@ -343,7 +344,7 @@ void SoundHooks::OnEmitSound(IRecipientFilter &filter, int iEntIndex, int iChann
|
||||
IPluginFunction *pFunc;
|
||||
cell_t res = static_cast<ResultType>(Pl_Continue);
|
||||
char buffer[PLATFORM_MAX_PATH];
|
||||
strcpy(buffer, pSample);
|
||||
ke::SafeStrcpy(buffer, sizeof(buffer), pSample);
|
||||
|
||||
char soundEntry[PLATFORM_MAX_PATH] = "";
|
||||
#if SOURCE_ENGINE >= SE_PORTAL2
|
||||
@@ -507,7 +508,7 @@ void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChan
|
||||
cell_t res = static_cast<ResultType>(Pl_Continue);
|
||||
cell_t sndlevel = static_cast<cell_t>(ATTN_TO_SNDLVL(flAttenuation));
|
||||
char buffer[PLATFORM_MAX_PATH];
|
||||
strcpy(buffer, pSample);
|
||||
ke::SafeStrcpy(buffer, sizeof(buffer), pSample);
|
||||
|
||||
char soundEntry[PLATFORM_MAX_PATH] = "";
|
||||
#if SOURCE_ENGINE >= SE_PORTAL2
|
||||
|
||||
Reference in New Issue
Block a user