-
Notifications
You must be signed in to change notification settings - Fork 66
[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
base: main
Are you sure you want to change the base?
[GEN][ZH] Fix buffer overrun and memory leaks in listbox properties of GUIEdit #796
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Also it looks like there are a ton of memory leaks in this code. Perhaps can tackle that in a follow up change. Some of these new char
can also be changed to stack buffers.
Yeah, I noticed that as well. I'll try to make some time to open a new pr for the memory leaks. Would you say that this would be the right approach? (Char vs. char and sizeof vs. 60)
EDIT: On second thought, it's probably preferable to put those memory leak fixes in this pr instead of a separate one. |
Yes this looks good.
You can do that yes. |
I think the memory leaks are handled now. |
GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/ListboxProperties.cpp
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test this change? Does it work?
char *percentages = new char[60]; | ||
char *tempStr = new char[60]; | ||
Char percentages[100]; | ||
Char tempStr[100]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
33
@@ -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[100]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the number 100 chosen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason other than that it's slightly bigger than it used to be.
char *percentages = new char[60]; | ||
char *token; | ||
GetDlgItemText(hWndDialog,EDIT_COLUMN_PERCENT,percentages,200); | ||
Char percentages[100]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this 100? Prior sizes were 60 or 200.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason other than that it's slightly bigger than it used to be.
GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/ListboxProperties.cpp
Outdated
Show resolved
Hide resolved
I haven't been able to test, so I'm afraid I can't answer that. |
It would would be good to give this a brief test before commit. |
Fixes a potential 'heap' overflow in GUIEdit: the actual buffer size is smaller than the claimed buffer size passed to GetDlgItemTextA.