From 54dad58468a9879fb44aff0d760bbd6c3288b812 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 18 Apr 2012 17:07:04 +0200 Subject: idevice: fix openssl initialization and handle error to avoid crash --- src/idevice.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idevice.c b/src/idevice.c index 91d67e6..a1cc013 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -559,6 +559,7 @@ static void internal_ssl_cleanup(ssl_data_t ssl_data) if (ssl_data->ctx) { SSL_CTX_free(ssl_data->ctx); } + openssl_init_done = 0; #else if (ssl_data->session) { gnutls_deinit(ssl_data->session); @@ -667,6 +668,11 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection) } /* Set up OpenSSL */ + if (openssl_init_done == 0) { + SSL_library_init(); + openssl_init_done = 1; + } + BIO *ssl_bio = BIO_new(BIO_s_socket()); if (!ssl_bio) { debug_info("ERROR: Could not create SSL bio."); @@ -674,11 +680,12 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection) } BIO_set_fd(ssl_bio, (int)(long)connection->data, BIO_NOCLOSE); - if (openssl_init_done == 0) { - SSL_library_init(); - openssl_init_done = 1; - } SSL_CTX *ssl_ctx = SSL_CTX_new(SSLv3_method()); + if (ssl_ctx == NULL) { + debug_info("ERROR: Could not create SSL context."); + BIO_free(ssl_bio); + return ret; + } BIO* membp; X509* rootCert = NULL; -- cgit v1.1-32-gdbae