rustls / rustls-ffi

Use Rustls from any language
Other
125 stars 30 forks source link

make rustls_slice_slice_bytes_len function unsafe #291

Closed kitcatier closed 1 year ago

kitcatier commented 1 year ago

https://github.com/rustls/rustls-ffi/blob/55df12216f0004af12c5967725a0b46d9c4bd466/src/rslice.rs#L80-L87 Hello, It is not a good choice to mark the entire function body as unsafe, which will make the caller ignore the safety requirements that the function parameters must guarantee, the developer who calls the start function may not notice this safety requirement. The unsafe function called needs to ensure that the parameter must be:

https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref

Marking them unsafe also means that callers must make sure they know what they're doing.

djc commented 1 year ago

If we're going to make it, we should probably document the guarantees you're listing here in the code?

jsha commented 1 year ago

Hi @kitcatier! Welcome to the rustls-ffi project, and thanks for the pull request.

All of the code in rustls-ffi is meant to be called by non-Rust code, and so uses raw pointers. So far we haven't chosen to mark the functions as unsafe for a couple of reasons:

We arrange for (non-Rust) callers of these function to uphold the safety guarantees by asking them to uphold a few properties:

So, my overall summary is: you make a good point, but the same arguments apply to all functions within rustls-ffi. If we mark one of these functions unsafe, we should really mark them all unsafe, and I'm not convinced that makes sense. But I'm willing to be convinced.