Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Safe CFRunLoop methods accept and dereference a raw pointer #648

Open
kevinmehall opened this issue Dec 4, 2023 · 0 comments · May be fixed by #650
Open

Safe CFRunLoop methods accept and dereference a raw pointer #648

kevinmehall opened this issue Dec 4, 2023 · 0 comments · May be fixed by #650

Comments

@kevinmehall
Copy link

The CFRunLoop methods add_timer, remove_timer contains_source, add_source, remove_source, contains_observer, add_observer, remove_observer accept an argument mode of type CFRunLoopMode, which is a type alias for *const __CFString. This parameter is passed on to the underlying functions which dereference it, so these methods are unsound because nothing prevents safe code from passing an invalid pointer.

I confirmed that the following line without unsafe segfaults:

run_loop.add_source(&source.unwrap(), 0x1234 as *mut _)

Ironically, correct usage requires unsafe, because the kCFRunLoopDefaultMode and kCFRunLoopCommonModes that are normally passed here are extern statics that requires unsafe to access.

kevinmehall added a commit to kevinmehall/core-foundation-rs that referenced this issue Dec 4, 2023
@kevinmehall kevinmehall linked a pull request Dec 4, 2023 that will close this issue
kevinmehall added a commit to kevinmehall/core-foundation-rs that referenced this issue Dec 4, 2023
kevinmehall added a commit to kevinmehall/core-foundation-rs that referenced this issue Aug 14, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant