diff options
author | Nikias Bassen | 2012-04-18 17:07:04 +0200 |
---|---|---|
committer | Nikias Bassen | 2012-04-18 17:07:04 +0200 |
commit | 54dad58468a9879fb44aff0d760bbd6c3288b812 (patch) | |
tree | 7a69e4859a7874b04e6c8c18e10b55646257c4d3 /src | |
parent | 8caf455ef9390bdd8ca29020611ef98238d3365b (diff) | |
download | libimobiledevice-54dad58468a9879fb44aff0d760bbd6c3288b812.tar.gz libimobiledevice-54dad58468a9879fb44aff0d760bbd6c3288b812.tar.bz2 |
idevice: fix openssl initialization and handle error to avoid crash
Diffstat (limited to 'src')
-rw-r--r-- | src/idevice.c | 15 |
1 files changed, 11 insertions, 4 deletions
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; |