Skip to content

Fix null pointer dereference in weak_ref::get() #1232

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 5 commits into from
Nov 21, 2022

Conversation

alvinhochun
Copy link
Contributor

There was a null pointer dereference bug in weak_ref::get(). This happens to not cause any issues with MSVC, but does crash with MinGW ABI when built with optimizations, because a cast in winrt::get_self would adjust the (null) pointer by an offset due to the different vtable layout, which ends up escaping null checks.

I didn't notice this earlier because all my tests happen to be unoptimized Debug builds. I tracked down this bug with the help of UBSan.

Because of this, I have also enabled Release build checks for llvm-mingw, and enabled ASan+UBSan for the tests in Debug builds.

This happens to not cause any issues with MSVC, but does crash with
MinGW ABI when built with optimizations, because a cast in
`winrt::get_self` would adjust the (null) pointer by an offset due to
the different vtable layout, which ends up escaping null checks.
@kennykerr kennykerr merged commit 37bd17f into microsoft:master Nov 21, 2022
@alvinhochun alvinhochun deleted the alvin/weakref-crash-fix branch December 11, 2022 16:48
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

Successfully merging this pull request may close these issues.

2 participants