diff --git a/Cargo.toml b/Cargo.toml index cb2807f..97250e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ An implementation of SSL streams for Tokio backed by OpenSSL [dependencies] futures-util = { version = "0.3", default-features = false } -openssl = "0.10.32" +openssl = "0.10.61" openssl-sys = "0.9" tokio = "1.0" diff --git a/build.rs b/build.rs index d3def6d..71e3670 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,4 @@ +#![allow(clippy::unusual_byte_groupings)] use std::env; fn main() { diff --git a/src/lib.rs b/src/lib.rs index 267638e..b4e2011 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ use openssl::ssl::{self, ErrorCode, ShutdownResult, Ssl, SslRef}; use std::fmt; use std::io::{self, Read, Write}; use std::pin::Pin; -use std::slice; use std::task::{Context, Poll}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; @@ -229,17 +228,11 @@ where buf: &mut ReadBuf<'_>, ) -> Poll> { self.with_context(ctx, |s| { - // This isn't really "proper", but rust-openssl doesn't currently expose a suitable interface even though - // OpenSSL itself doesn't require the buffer to be initialized. So this is good enough for now. - let slice = unsafe { - let buf = buf.unfilled_mut(); - slice::from_raw_parts_mut(buf.as_mut_ptr().cast::(), buf.len()) - }; - match cvt(s.read(slice))? { + // SAFETY: read_uninit does not de-initialize the buffer. + match cvt(s.read_uninit(unsafe { buf.unfilled_mut() }))? { Poll::Ready(nread) => { - unsafe { - buf.assume_init(nread); - } + // SAFETY: read_uninit guarantees that nread bytes have been initialized. + unsafe { buf.assume_init(nread) }; buf.advance(nread); Poll::Ready(Ok(())) }