Skip to content

Commit 228ebdd

Browse files
authored
bugfix: Fix global-buffer-overflow in WorldBuilder (MapObjectProps class) (#1725)
1 parent 8db49bf commit 228ebdd

39 files changed

+130
-130
lines changed

Generals/Code/Tools/WorldBuilder/include/StdAfx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <afxcmn.h> // MFC support for Windows Common Controls
4343
#endif // _AFX_NO_AFXCMN_SUPPORT
4444

45-
45+
#include <Utility/stdio_adapter.h>
4646

4747

4848
//{{AFX_INSERT_LOCATION}}

Generals/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ BOOL BaseBuildProps::OnInitDialog()
6666
// add health
6767
CWnd* pHealth = GetDlgItem(IDC_MAPOBJECT_StartingHealthEdit);
6868
static char buff[12];
69-
sprintf(buff, "%d", m_health);
69+
snprintf(buff, ARRAY_SIZE(buff), "%d", m_health);
7070
pHealth->SetWindowText(buff);
7171

7272
CButton* pItem;

Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare
208208
// Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles;
209209

210210
char label[_MAX_PATH];
211-
sprintf(label, "%s", buffer);
211+
snprintf(label, ARRAY_SIZE(label), "%s", buffer);
212212

213213

214214
if( doAdd )

Generals/Code/Tools/WorldBuilder/src/BuildList.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,16 @@ void BuildList::OnSelchangeBuildList()
449449
PointerTool::clearSelection(); // unselect other stuff.
450450
if (pBuildInfo) {
451451
CWnd *edit;
452-
static char buff[12];
452+
static char buff[32];
453453
pBuildInfo->setSelected(true);
454454

455455
m_angle = pBuildInfo->getAngle() * 180/PI;
456-
sprintf(buff, "%0.2f", m_angle);
456+
snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle);
457457
edit = GetDlgItem(IDC_MAPOBJECT_Angle);
458458
edit->SetWindowText(buff);
459459

460460
m_height = pBuildInfo->getLocation()->z;
461-
sprintf(buff, "%0.2f", m_height);
461+
snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height);
462462
edit = GetDlgItem(IDC_MAPOBJECT_ZOffset);
463463
edit->SetWindowText(buff);
464464

@@ -638,19 +638,19 @@ void BuildList::PopSliderChanged(const long sliderID, long theVal)
638638
{
639639
// CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
640640
CWnd* edit;
641-
static char buff[12];
641+
static char buff[32];
642642
switch (sliderID) {
643643
case IDC_HEIGHT_POPUP:
644644
m_height = theVal;
645-
sprintf(buff, "%0.2f", m_height);
645+
snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height);
646646
edit = GetDlgItem(IDC_MAPOBJECT_ZOffset);
647647
edit->SetWindowText(buff);
648648
OnChangeZOffset();
649649
break;
650650

651651
case IDC_ANGLE_POPUP:
652652
m_angle = theVal;
653-
sprintf(buff, "%0.2f", m_angle);
653+
snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle);
654654
edit = GetDlgItem(IDC_MAPOBJECT_Angle);
655655
edit->SetWindowText(buff);
656656
break;

Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ void EditParameter::readFontFile( const char *filename )
13321332
{
13331333
char buffer[ 1024 ];
13341334

1335-
sprintf( buffer, "Warning: The font '%s' Size: '%d' Bold: '%d', specified in the config file could not be loaded. Does that font exist?",
1335+
snprintf( buffer, ARRAY_SIZE(buffer), "Warning: The font '%s' Size: '%d' Bold: '%d', specified in the config file could not be loaded. Does that font exist?",
13361336
fontBuffer, size, bold );
13371337
//MessageBox( m_appHWnd, buffer, "Cannot Load Font", MB_OK );
13381338

Generals/Code/Tools/WorldBuilder/src/FeatherOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void FeatherOptions::OnChangeSizeEdit()
134134
if (1==sscanf(buffer, "%d", &width)) {
135135
m_currentFeather = width;
136136
FeatherTool::setFeather(m_currentFeather);
137-
sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR);
137+
snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR);
138138
pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL);
139139
if (pEdit) pEdit->SetWindowText(buffer);
140140
}

Generals/Code/Tools/WorldBuilder/src/GroveOptions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,35 +266,35 @@ void GroveOptions::_setDefaultRatios(void)
266266
CWnd* pWnd = GetDlgItem(IDC_Grove_Per1);
267267
if (pWnd) {
268268
defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio1", 0);
269-
sprintf(buff, "%d", defaultRatio);
269+
snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio);
270270
pWnd->SetWindowText(buff);
271271
}
272272

273273
pWnd = GetDlgItem(IDC_Grove_Per2);
274274
if (pWnd) {
275275
defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio2", 0);
276-
sprintf(buff, "%d", defaultRatio);
276+
snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio);
277277
pWnd->SetWindowText(buff);
278278
}
279279

280280
pWnd = GetDlgItem(IDC_Grove_Per3);
281281
if (pWnd) {
282282
defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio3", 0);
283-
sprintf(buff, "%d", defaultRatio);
283+
snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio);
284284
pWnd->SetWindowText(buff);
285285
}
286286

287287
pWnd = GetDlgItem(IDC_Grove_Per4);
288288
if (pWnd) {
289289
defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio4", 0);
290-
sprintf(buff, "%d", defaultRatio);
290+
snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio);
291291
pWnd->SetWindowText(buff);
292292
}
293293

294294
pWnd = GetDlgItem(IDC_Grove_Per5);
295295
if (pWnd) {
296296
defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio5", 0);
297-
sprintf(buff, "%d", defaultRatio);
297+
snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio);
298298
pWnd->SetWindowText(buff);
299299
}
300300
}
@@ -308,7 +308,7 @@ void GroveOptions::_setDefaultNumTrees(void)
308308

309309
int defaultNumTrees = AfxGetApp()->GetProfileInt("GroveOptions", "NumberofTrees", 10);
310310
static char buff[ARBITRARY_BUFF_SIZE];
311-
sprintf(buff, "%d", defaultNumTrees);
311+
snprintf(buff, ARRAY_SIZE(buff), "%d", defaultNumTrees);
312312

313313
pWnd->SetWindowText(buff);
314314
}
@@ -379,7 +379,7 @@ void GroveOptions::_updateTreeWeights(void)
379379

380380
pWnd = GetDlgItem(IDC_Grove_PerTotal);
381381
if (pWnd) {
382-
sprintf(buff, "%d", val);
382+
snprintf(buff, ARRAY_SIZE(buff), "%d", val);
383383
pWnd->SetWindowText(buff);
384384
}
385385
}

Generals/Code/Tools/WorldBuilder/src/LayersList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void LayersList::OnNewLayer()
588588
}
589589

590590
static char buffer[1024];
591-
sprintf(buffer, "%s %d", TheDefaultNewLayerName.c_str(), newLayerNum);
591+
snprintf(buffer, ARRAY_SIZE(buffer), "%s %d", TheDefaultNewLayerName.c_str(), newLayerNum);
592592
addLayerNamed(buffer);
593593

594594
HTREEITEM newItem = pTree->InsertItem(buffer, 0, 0);

Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ BOOL MeshMoldOptions::OnInitDialog()
142142

143143
void MeshMoldOptions::setHeight(Real height)
144144
{
145-
char buffer[50];
146-
sprintf(buffer, "%.2f", height);
145+
char buffer[32];
146+
snprintf(buffer, ARRAY_SIZE(buffer), "%.2f", height);
147147
m_currentHeight = height;
148148
if (m_staticThis && !m_staticThis->m_updating) {
149149
CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT);
@@ -154,8 +154,8 @@ void MeshMoldOptions::setHeight(Real height)
154154

155155
void MeshMoldOptions::setScale(Real scale)
156156
{
157-
char buffer[50];
158-
sprintf(buffer, "%d", (int)floor(scale*100));
157+
char buffer[12];
158+
snprintf(buffer, ARRAY_SIZE(buffer), "%d", (int)floor(scale*100));
159159
m_currentScale = scale;
160160
if (m_staticThis && !m_staticThis->m_updating) {
161161
CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SCALE_EDIT);
@@ -166,8 +166,8 @@ void MeshMoldOptions::setScale(Real scale)
166166

167167
void MeshMoldOptions::setAngle(Int angle)
168168
{
169-
char buffer[50];
170-
sprintf(buffer, "%d", angle);
169+
char buffer[12];
170+
snprintf(buffer, ARRAY_SIZE(buffer), "%d", angle);
171171
m_currentAngle = angle;
172172
if (m_staticThis && !m_staticThis->m_updating) {
173173
CWnd *pEdit = m_staticThis->GetDlgItem(IDC_ANGLE_EDIT);

Generals/Code/Tools/WorldBuilder/src/MoundOptions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ void MoundOptions::setWidth(Int width)
7878

7979
void MoundOptions::setHeight(Int height)
8080
{
81-
char buffer[50];
82-
sprintf(buffer, "%d", height);
81+
char buffer[12];
82+
snprintf(buffer, ARRAY_SIZE(buffer), "%d", height);
8383
m_currentHeight = height;
8484
if (m_staticThis && !m_staticThis->m_updating) {
8585
CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT);
@@ -129,7 +129,7 @@ void MoundOptions::OnChangeFeatherEdit()
129129
if (1==sscanf(buffer, "%d", &feather)) {
130130
m_currentFeather = feather;
131131
MoundTool::setFeather(m_currentFeather);
132-
sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR);
132+
snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR);
133133
pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_LABEL);
134134
if (pEdit) pEdit->SetWindowText(buffer);
135135
}
@@ -152,7 +152,7 @@ void MoundOptions::OnChangeSizeEdit()
152152
if (1==sscanf(buffer, "%d", &width)) {
153153
m_currentWidth = width;
154154
MoundTool::setWidth(m_currentWidth);
155-
sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR);
155+
snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR);
156156
pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL);
157157
if (pEdit) pEdit->SetWindowText(buffer);
158158
}
@@ -175,7 +175,7 @@ void MoundOptions::OnChangeHeightEdit()
175175
if (1==sscanf(buffer, "%d", &height)) {
176176
m_currentHeight = height;
177177
MoundTool::setMoundHeight(m_currentHeight);
178-
sprintf(buffer, "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE);
178+
snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE);
179179
pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_LABEL);
180180
if (pEdit) pEdit->SetWindowText(buffer);
181181
}

0 commit comments

Comments
 (0)