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

Fix use after free errors #177

Merged
merged 8 commits into from
Jun 13, 2024
Merged

Fix use after free errors #177

merged 8 commits into from
Jun 13, 2024

Conversation

yamadapc
Copy link
Contributor

Fixes a few cases where use after free could happen, and one where it can be easily reproduced.

When using the FSEvents back-end, both the Watcher and a State pointers are passed as part of the context parameter to a C style callback.

Both of these pointers may be free-ed before the callback is called before this commit.

After this commit, these two pointers, as well as all most others in the codebase are replaced with shared_ptr.

This is a lazy fix and goes against C++ core guidelines - "F.7". (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-smart)

A secondary pass would use reference counting only in the shared ownership cases. For most back-ends this shared ownership happens on: error types, subscription maps/sets and state structs. (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-owner)

Fixes a few cases where use after free could happen, and one where it can be
easily reproduced.

When using the FSEvents back-end, both the `Watcher` and a `State` pointers are
passed as part of the context parameter to a C style callback.

Both of these pointers may be free-ed before the callback is called before this
commit.

After this commit, these two pointers, as well as all most others in the
codebase are replaced with `shared_ptr`.

This is a lazy fix and goes against C++ core guidelines - "F.7".

A secondary pass would use reference counting only in the shared ownership
cases. For most back-ends this shared ownership happens on: error types,
subscription maps/sets and state structs.
@yamadapc yamadapc marked this pull request as ready for review June 11, 2024 01:30
@yamadapc yamadapc marked this pull request as draft June 11, 2024 01:38
@yamadapc
Copy link
Contributor Author

I still need to:

  • Fix tests
  • Fix compilation on operating systems other than macOS

While it is possible that use after free happens on other back-ends, main bug I can reproduce is related to macOS fsevents callback.

@yamadapc
Copy link
Contributor Author

@devongovett I get errors on the wasm/index.mjs file, due to missing syscall_open definition. Do you know how that file was generated?

@devongovett devongovett merged commit e9af634 into master Jun 13, 2024
8 checks passed
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.

10 participants