Skip to content

Commit a9fd1d2

Browse files
committed
[GEN][ZH] Prevent unlikely buffer overrun while writing to 'newPts' in PolygonTrigger::reallocate()
1 parent 6026f2c commit a9fd1d2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ void PolygonTrigger::reallocate(void)
9595
{
9696
DEBUG_ASSERTCRASH(m_numPoints <= m_sizePoints, ("Invalid m_numPoints."));
9797
if (m_numPoints == m_sizePoints) {
98+
if (m_sizePoints > INT_MAX / 2) {
99+
DEBUG_CRASH(("Too many points to allocate."));
100+
return;
101+
}
98102
// Reallocate.
99103
m_sizePoints += m_sizePoints;
100104
ICoord3D *newPts = NEW ICoord3D[m_sizePoints];

GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void PolygonTrigger::reallocate(void)
9797
{
9898
DEBUG_ASSERTCRASH(m_numPoints <= m_sizePoints, ("Invalid m_numPoints."));
9999
if (m_numPoints == m_sizePoints) {
100+
if (m_sizePoints > INT_MAX / 2) {
101+
DEBUG_CRASH(("Too many points to allocate."));
102+
return;
103+
}
100104
// Reallocate.
101105
m_sizePoints += m_sizePoints;
102106
ICoord3D *newPts = NEW ICoord3D[m_sizePoints];

0 commit comments

Comments
 (0)