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

Fixed used after free bug in ffi_type_array_create #23

Merged
merged 2 commits into from
May 6, 2021

Conversation

xtldr
Copy link
Contributor

@xtldr xtldr commented May 5, 2021

In middle::types::ffi_type_array_create the ffi_type of element is copied to new, but when element is dropped at the end of the loop, the ffi_type is deallocated while still readable from new.

If we add forget(element), the ffi_type won't be deallocated. Since Type::drop only deallocates it's ffi_type, this should be safe because the ffi_type is now owned by the resulting TypeArray.

@@ -102,6 +102,7 @@ where
let new = ffi_type_array_create_empty(size);
for (i, element) in elements.enumerate() {
*new.add(i) = *element.0;
forget(element);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xtldr forget itself isn't imported, instead std::mem as a whole is imported. This means you have to use mem::forget(element) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yorickpeterse Yes of course. I shouldn't use the online editor to create patches without testing, even for one liners. I have fixed it now.

@yorickpeterse
Copy link
Collaborator

@xtldr Thanks!

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.

None yet

2 participants