Skip to content
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

Integer overflow when calculating AllocMem() size #84

Open
szsam opened this issue May 25, 2023 · 1 comment
Open

Integer overflow when calculating AllocMem() size #84

szsam opened this issue May 25, 2023 · 1 comment

Comments

@szsam
Copy link

szsam commented May 25, 2023

twin/server/resize.cpp

Lines 127 to 129 in b6e4e4b

if (x > 0 && y > 0) {
if (!(saveNewCont = NewCont = (tcell *)AllocMem(x * y * sizeof(tcell))))
return false;

This allocation size is derived from user input and the multiplication might overflow.
Consider adding upper bounds for x and y, e.g.

 if (x > 0 && y > 0 && x < 1000 && y < 1000) { 
   if (!(saveNewCont = NewCont = (tcell *)AllocMem(x * y * sizeof(tcell)))) 
     return false; 
@cosmos72
Copy link
Owner

Thanks for spotting this!
Yes, that code shoud check for overflows before the multiplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants