Skip to content

[GEN][ZH] Fix buffer overrun and memory leaks in listbox properties of GUIEdit #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,8 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,

if(newColumns > 1)
{
char *percentages = new char[60];
char *token;
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,200);
Char percentages[200];
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,sizeof(percentages));
if(strlen(percentages) == 0)
{
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);
Expand All @@ -612,7 +611,7 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
Int *newPercentages = new Int[newColumns];
Int i = 0;
Int total = 0;
token = strtok( percentages, "," );
Char *token = strtok( percentages, "," );
while( token != NULL )
{
newPercentages[i] = atoi(token);
Expand All @@ -621,23 +620,26 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
i++;
if(i > newColumns && token)
{
Char *whoopsMsg = new char[250];
Char whoopsMsg[250];
sprintf(whoopsMsg,"You have Specified %d columns but I have read in more then that for the percentages, please double check your data", newColumns);
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
delete[] newPercentages;
return 0;
}
else if( i < newColumns && !token )
{
Char *whoopsMsg = new char[250];
Char whoopsMsg[250];
sprintf(whoopsMsg,"You have Specified %d columns but I have read in only %d for the percentages, please double check your data", newColumns, i );
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
delete[] newPercentages;
return 0;
}
else if((total > 100 ) || (total < 100 && !token ))
{
Char *whoopsMsg = new char[250];
Char whoopsMsg[250];
sprintf(whoopsMsg,"Please Double check to make sure your percentages add up to 100.");
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
delete[] newPercentages;
return 0;
}
}
Expand Down Expand Up @@ -941,8 +943,8 @@ HWND InitListboxPropertiesDialog( GameWindow *window )
SetDlgItemInt( dialog, EDIT_NUM_COLUMNS, listData->columns, FALSE );
if(listData->columns > 1)
{
char *percentages = new char[60];
char *tempStr = new char[60];
Char percentages[200];
Char tempStr[33];
sprintf(percentages,"%d",listData->columnWidthPercentage[0]);
for(Int i = 1; i < listData->columns; i++ )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,8 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,

if(newColumns > 1)
{
char *percentages = new char[60];
char *token;
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,200);
Char percentages[200];
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,sizeof(percentages));
if(strlen(percentages) == 0)
{
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);
Expand All @@ -612,7 +611,7 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
Int *newPercentages = new Int[newColumns];
Int i = 0;
Int total = 0;
token = strtok( percentages, "," );
Char *token = strtok( percentages, "," );
while( token != NULL )
{
newPercentages[i] = atoi(token);
Expand All @@ -621,23 +620,26 @@ static LRESULT CALLBACK listboxPropertiesCallback( HWND hWndDialog,
i++;
if(i > newColumns && token)
{
Char *whoopsMsg = new char[250];
Char whoopsMsg[250];
sprintf(whoopsMsg,"You have Specified %d columns but I have read in more then that for the percentages, please double check your data", newColumns);
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
delete[] newPercentages;
return 0;
}
else if( i < newColumns && !token )
{
Char *whoopsMsg = new char[250];
Char whoopsMsg[250];
sprintf(whoopsMsg,"You have Specified %d columns but I have read in only %d for the percentages, please double check your data", newColumns, i );
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
delete[] newPercentages;
return 0;
}
else if((total > 100 ) || (total < 100 && !token ))
{
Char *whoopsMsg = new char[250];
Char whoopsMsg[250];
sprintf(whoopsMsg,"Please Double check to make sure your percentages add up to 100.");
MessageBox(NULL, whoopsMsg,"Whoops",MB_OK | MB_ICONSTOP | MB_APPLMODAL);
delete[] newPercentages;
return 0;
}
}
Expand Down Expand Up @@ -941,8 +943,8 @@ HWND InitListboxPropertiesDialog( GameWindow *window )
SetDlgItemInt( dialog, EDIT_NUM_COLUMNS, listData->columns, FALSE );
if(listData->columns > 1)
{
char *percentages = new char[60];
char *tempStr = new char[60];
Char percentages[200];
Char tempStr[33];
sprintf(percentages,"%d",listData->columnWidthPercentage[0]);
for(Int i = 1; i < listData->columns; i++ )
{
Expand Down
Loading