Skip to content

Commit d3bed71

Browse files
authored
[GEN][ZH] Fix buffer overrun and memory leaks in listbox properties of GUIEdit (#796)
1 parent 4f1f489 commit d3bed71

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/ListboxProperties.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,8 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
600600

601601
if(newColumns > 1)
602602
{
603-
char *percentages = new char[60];
604-
char *token;
605-
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,200);
603+
Char percentages[200];
604+
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,sizeof(percentages));
606605
if(strlen(percentages) == 0)
607606
{
608607
MessageBox(NULL,"You have specified a column amount greater then 1, please enter the same about of percentages","whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
@@ -612,7 +611,7 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
612611
Int *newPercentages = new Int[newColumns];
613612
Int i = 0;
614613
Int total = 0;
615-
token = strtok( percentages, "," );
614+
Char *token = strtok( percentages, "," );
616615
while( token != NULL )
617616
{
618617
newPercentages[i] = atoi(token);
@@ -621,23 +620,26 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
621620
i++;
622621
if(i > newColumns && token)
623622
{
624-
Char *whoopsMsg = new char[250];
623+
Char whoopsMsg[250];
625624
sprintf(whoopsMsg,"You have Specified %d columns but I have read in more then that for the percentages, please double check your data", newColumns);
626625
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
626+
delete[] newPercentages;
627627
return 0;
628628
}
629629
else if( i < newColumns && !token )
630630
{
631-
Char *whoopsMsg = new char[250];
631+
Char whoopsMsg[250];
632632
sprintf(whoopsMsg,"You have Specified %d columns but I have read in only %d for the percentages, please double check your data", newColumns, i );
633633
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
634+
delete[] newPercentages;
634635
return 0;
635636
}
636637
else if((total > 100 ) || (total < 100 && !token ))
637638
{
638-
Char *whoopsMsg = new char[250];
639+
Char whoopsMsg[250];
639640
sprintf(whoopsMsg,"Please Double check to make sure your percentages add up to 100.");
640641
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
642+
delete[] newPercentages;
641643
return 0;
642644
}
643645
}
@@ -941,8 +943,8 @@ HWND InitListboxPropertiesDialog( GameWindow *window )
941943
SetDlgItemInt( dialog, EDIT_NUM_COLUMNS, listData->columns, FALSE );
942944
if(listData->columns > 1)
943945
{
944-
char *percentages = new char[60];
945-
char *tempStr = new char[60];
946+
Char percentages[200];
947+
Char tempStr[33];
946948
sprintf(percentages,"%d",listData->columnWidthPercentage[0]);
947949
for(Int i = 1; i < listData->columns; i++ )
948950
{

GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/ListboxProperties.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,8 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
600600

601601
if(newColumns > 1)
602602
{
603-
char *percentages = new char[60];
604-
char *token;
605-
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,200);
603+
Char percentages[200];
604+
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,sizeof(percentages));
606605
if(strlen(percentages) == 0)
607606
{
608607
MessageBox(NULL,"You have specified a column amount greater then 1, please enter the same about of percentages","whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
@@ -612,7 +611,7 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
612611
Int *newPercentages = new Int[newColumns];
613612
Int i = 0;
614613
Int total = 0;
615-
token = strtok( percentages, "," );
614+
Char *token = strtok( percentages, "," );
616615
while( token != NULL )
617616
{
618617
newPercentages[i] = atoi(token);
@@ -621,23 +620,26 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
621620
i++;
622621
if(i > newColumns && token)
623622
{
624-
Char *whoopsMsg = new char[250];
623+
Char whoopsMsg[250];
625624
sprintf(whoopsMsg,"You have Specified %d columns but I have read in more then that for the percentages, please double check your data", newColumns);
626625
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
626+
delete[] newPercentages;
627627
return 0;
628628
}
629629
else if( i < newColumns && !token )
630630
{
631-
Char *whoopsMsg = new char[250];
631+
Char whoopsMsg[250];
632632
sprintf(whoopsMsg,"You have Specified %d columns but I have read in only %d for the percentages, please double check your data", newColumns, i );
633633
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
634+
delete[] newPercentages;
634635
return 0;
635636
}
636637
else if((total > 100 ) || (total < 100 && !token ))
637638
{
638-
Char *whoopsMsg = new char[250];
639+
Char whoopsMsg[250];
639640
sprintf(whoopsMsg,"Please Double check to make sure your percentages add up to 100.");
640641
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
642+
delete[] newPercentages;
641643
return 0;
642644
}
643645
}
@@ -941,8 +943,8 @@ HWND InitListboxPropertiesDialog( GameWindow *window )
941943
SetDlgItemInt( dialog, EDIT_NUM_COLUMNS, listData->columns, FALSE );
942944
if(listData->columns > 1)
943945
{
944-
char *percentages = new char[60];
945-
char *tempStr = new char[60];
946+
Char percentages[200];
947+
Char tempStr[33];
946948
sprintf(percentages,"%d",listData->columnWidthPercentage[0]);
947949
for(Int i = 1; i < listData->columns; i++ )
948950
{

0 commit comments

Comments
 (0)