servo / rust-webvr

UNMAINTAINED - WebVR API implementation for servo.
Mozilla Public License 2.0
106 stars 23 forks source link

JNIScope is unsound #20

Open nox opened 6 years ago

nox commented 6 years ago

JNIScope is a struct with only public fields (which means anyone is free to build new ones), but its Drop implementation dereferences raw pointers to call FFI functions on them. this is unsound.

https://github.com/MortimerGoro/rust-webvr/blob/cab969ee734908ebaac7667bbd4cd903e2135dd5/rust-webvr-api/src/jni_utils.rs#L9-L13

https://github.com/MortimerGoro/rust-webvr/blob/cab969ee734908ebaac7667bbd4cd903e2135dd5/rust-webvr-api/src/jni_utils.rs#L90-L98

MortimerGoro commented 6 years ago

Thanks for reviewing this. Yep, we can make the fields private and add getter functions to prevent users from creating JNIScopes without attach()