steffengy / schannel-rs

Schannel API-bindings for rust (provides an interface for native SSL/TLS using windows APIs)
MIT License
49 stars 51 forks source link

Prevent undefined behavior in context_buffer.rs #81

Closed DouglasDwyer closed 2 years ago

DouglasDwyer commented 2 years ago

In some situations, this crate may attempt to dereference a ContextBuffer as a &[u8] when the context buffer's underlying pointer is null. According to the docs for slice::from_raw_parts, this is undefined behavior, and leads to a crash in debug mode on my machine. To work around this, I've added a check for empty context buffers, which returns a constant empty slice instead. This seems to work correctly, but as I'm not familiar with this library, there may be some other invariant being violated. As such, I'm submitting this PR in the hopes that this solves the issue, or at least stimulates some discussion about the problem. Thanks!