glutin icon indicating copy to clipboard operation
glutin copied to clipboard

[Bug] Getting opengl function address panics if the address contains a null terminator

Open morr0ne opened this issue 2 years ago • 2 comments

Window.get_proc_address accepts a &str which gets then converted to a CString without checking for null bytes and just calling unwrap. Passing a &str with internal null bytes will crash the program. The conversion can also be expensive considering that most opengl loaders will use a CString/CStr directly. This means that in most cases the following conversion happens: CString => &str => CString.

it's probably a good idea for get_proc_address to ask directly for a &CStr and let the library user handle the conversion if necessary.

related #1314

morr0ne avatar Apr 28 '22 14:04 morr0ne

That makes sense, could probably change that.

kchibisov avatar Apr 28 '22 14:04 kchibisov

Upon further inspection it looks like some tools like the one used in the examples (gl_generator) use &str for loading, hence probably why that was used. Making a change like that probably also means changing the generator used. Phosporus seems to be the best alternative, it used by glow and transitively by bigger projects like wgpu and bevy.

morr0ne avatar Apr 29 '22 20:04 morr0ne

Fixed in https://github.com/rust-windowing/glutin/pull/1435.

kchibisov avatar Sep 03 '22 06:09 kchibisov