Skip to content

Commit 33fffd7

Browse files
committed
lib: make _SSL_new constructor fallible
The `SSL_new` entry point is described as returning `NULL` for error conditions. Prior to this commit the only possible error was from the `SSL_CTX` Mutex being poisoned - the `SSL::new` constructor was infallible. To support loading certs on-demand from default locations when constructing a `SSL` from a `SSL_CTX` this commit updates the `SSL::new` constructor fn to be fallible. We convert any error to a `NULL` return in the entry-point wrapper.
1 parent 7ed3727 commit 33fffd7

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

rustls-libssl/src/entry.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,17 @@ entry! {
299299
pub fn _SSL_new(ctx: *mut SSL_CTX) -> *mut SSL {
300300
let ctx = try_clone_arc!(ctx);
301301

302-
ctx.lock()
303-
.ok()
304-
.map(|c| to_arc_mut_ptr(Mutex::new(crate::Ssl::new(ctx.clone(), &c))))
305-
.unwrap_or_else(ptr::null_mut)
302+
let ssl_ctx = match ctx.lock().ok() {
303+
Some(ssl_ctx) => ssl_ctx,
304+
None => return ptr::null_mut(),
305+
};
306+
307+
let ssl = match crate::Ssl::new(ctx.clone(), &ssl_ctx).ok() {
308+
Some(ssl) => ssl,
309+
None => return ptr::null_mut(),
310+
};
311+
312+
to_arc_mut_ptr(Mutex::new(ssl))
306313
}
307314
}
308315

rustls-libssl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ struct Ssl {
297297
}
298298

299299
impl Ssl {
300-
fn new(ctx: Arc<Mutex<SslContext>>, inner: &SslContext) -> Self {
301-
Self {
300+
fn new(ctx: Arc<Mutex<SslContext>>, inner: &SslContext) -> Result<Self, error::Error> {
301+
Ok(Self {
302302
ctx,
303303
raw_options: inner.raw_options,
304304
mode: inner.method.mode(),
@@ -313,7 +313,7 @@ impl Ssl {
313313
peer_cert: None,
314314
peer_cert_chain: None,
315315
shutdown_flags: ShutdownFlags::default(),
316-
}
316+
})
317317
}
318318

319319
fn get_options(&self) -> u64 {

0 commit comments

Comments
 (0)