arturoc / gstreamer1.0-rs

Idiomatic bindings for Gstreamer on Rust.
MIT License
36 stars 14 forks source link

Memory corruption due to incorrect handling of C strings #10

Closed Blei closed 8 years ago

Blei commented 8 years ago

to_c_str! (https://github.com/arturoc/gstreamer1.0-rs/blob/f6a0c6a369db530288701e79a2d45f017544e6e3/src/util.rs#L19) is handling lifetimes of c strings incorrectly. The return value of as_ptr() is only valid during the lifetime of the underlying CString type. This can cause silent data corruption in situations where the called C code holds on to the string for a longer time (I noticed this because the playbin element that I created with PlayBin::new() changed name during the runtime of my program). There are 2 solutions:

arturoc commented 8 years ago

thanks, i think there were only a couple of cases were it was being used in an unsafe manner but i've removed the macro completely and use CString explecetly since it allowed such a case

Blei commented 8 years ago

Thanks for the quick fix!