Increment SSL_CTX's reference count in Ssl::get_ssl_context()

Without this, whenever the returned SslContext is released,
the refcount of the underlying SSL_CTX will decrease and it
will be freed too soon
This commit is contained in:
Geoffroy Couprie 2015-12-03 12:26:55 +01:00
parent 7835ea1c90
commit 6850c810d3
3 changed files with 8 additions and 0 deletions

View File

@ -69,4 +69,6 @@ extern {
pub fn SSL_CTX_set_tlsext_servername_callback(ssl: *mut SSL_CTX, callback: Option<extern fn()>);
#[link_name = "SSL_CTX_set_tlsext_servername_arg_shim"]
pub fn SSL_CTX_set_tlsext_servername_arg(ssl: *mut SSL_CTX, arg: *const c_void);
#[link_name = "SSL_CTX_increment_refcount_shim"]
pub fn SSL_CTX_increment_refcount(ssl: *mut SSL_CTX) -> c_long;
}

View File

@ -123,6 +123,11 @@ long SSL_CTX_set_tlsext_servername_arg_shim(SSL_CTX *ctx, void* arg) {
return SSL_CTX_set_tlsext_servername_arg(ctx, arg);
}
long SSL_CTX_increment_refcount_shim(SSL_CTX *ctx) {
int i = CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
return i;
}
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
int SSL_CTX_set_ecdh_auto_shim(SSL_CTX *ctx, int onoff) {
return SSL_CTX_set_ecdh_auto(ctx, onoff);

View File

@ -995,6 +995,7 @@ impl Ssl {
/// obtain the context corresponding to the current connection
pub fn get_ssl_context(&self) -> SslContext {
let ssl_ctx = unsafe { ffi::SSL_get_SSL_CTX(self.ssl) };
let count = unsafe { ffi_extras::SSL_CTX_increment_refcount(ssl_ctx) };
SslContext { ctx: ssl_ctx }
}
}