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

Fix buffer overflows #1121

Merged
merged 10 commits into from Feb 2, 2015

Conversation

Projects
None yet
4 participants
@bpay
Contributor

bpay commented Jan 21, 2015

Fixes about 15 actual buffer overflows due to incorrect use of sizeof on UTF16 strings, and provides safer functions to use for static sized buffers. We found that some of these (in fileDialog.cpp) were regularly writing into caller's stack frames.

@crabmusket crabmusket added the Bug label Jan 21, 2015

@Azaezel

This comment has been minimized.

Show comment
Hide comment
@Azaezel

Azaezel Jan 23, 2015

Contributor

verified

Contributor

Azaezel commented Jan 23, 2015

verified

bpay added some commits Jan 20, 2015

Fix buffer overflows due to incorrect use of sizeof
A snippet of example code:

UTF16 pszFilter[1024];
...
convertUTF8toUTF16((UTF8 *)mData.mFilters, pszFilter, sizeof(pszFilter));

Since the conversion function is expecting the third parameter to be the
length in 16-bit characters, *not* bytes, this results in the function
writing outside the bounds of the output array.

To make this less likely to happen in the future (I hope), I've provided a
template function that infers the correct size of a static array, so it's
no longer necessary to pass the size in most cases. The sized function has
been renamed with an "N" suffix to hopefully encourage this use.

This bug was caught due to a warning from MSVC about stack corruption
occurring in codeBlock::exec(), after opening a file open dialog twice in
succession. After some hunting, I found that this was due to
FileDialog::Execute() passing incorrect buffer sizes to the conversion
function, which resulted in the function writing a null terminator into
some memory that happened to be in the stack frame of codeBlock::exec()!
Remove unnecessary null termination
UTF16Cache::copyToBuffer() is already adding a null terminator
Rename the memory allocating versions to make prev error less likely
The behavior is different enough that these shouldn't be overloaded
with the non-allocating verions. Also makes it more obvious what is
going on to the caller.
@bpay

This comment has been minimized.

Show comment
Hide comment
@bpay

bpay Jan 26, 2015

Contributor

Rebased against current development

Contributor

bpay commented Jan 26, 2015

Rebased against current development

@LuisAntonRebollo

This comment has been minimized.

Show comment
Hide comment
@LuisAntonRebollo

LuisAntonRebollo Feb 2, 2015

Contributor

Great work :)

👍

Contributor

LuisAntonRebollo commented Feb 2, 2015

Great work :)

👍

LuisAntonRebollo added a commit that referenced this pull request Feb 2, 2015

@LuisAntonRebollo LuisAntonRebollo merged commit cc9be50 into GarageGames:development Feb 2, 2015

1 check passed

default Merged build finished.
Details

@crabmusket crabmusket added this to the 3.7 milestone Feb 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment