From 9305762fcd16956d23451a0b2d43dabb6552d4aa Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Tue, 31 Jul 2018 16:15:01 +0200 Subject: [PATCH] Remove internal calls to ssh_init Since the call is made automatically when the library is loaded, these calls are no longer required (if the library is not linked statically). Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Andreas Schneider --- src/bind.c | 5 ----- src/client.c | 3 --- src/pki_crypto.c | 10 ---------- src/pki_gcrypt.c | 5 ----- src/pki_mbedcrypto.c | 4 ---- tests/unittests/torture_threads_pki_rsa.c | 6 ++++++ 6 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/bind.c b/src/bind.c index 7b350d9a..b07dd574 100644 --- a/src/bind.c +++ b/src/bind.c @@ -253,11 +253,6 @@ int ssh_bind_listen(ssh_bind sshbind) { socket_t fd; int rc; - if (ssh_init() < 0) { - ssh_set_error(sshbind, SSH_FATAL, "ssh_init() failed"); - return -1; - } - if (sshbind->rsa == NULL && sshbind->dsa == NULL && sshbind->ecdsa == NULL && diff --git a/src/client.c b/src/client.c index 40c238aa..00cbad38 100644 --- a/src/client.c +++ b/src/client.c @@ -505,9 +505,6 @@ int ssh_connect(ssh_session session) { session->alive = 0; session->client = 1; - if (ssh_init() < 0) { - return SSH_ERROR; - } if (session->opts.fd == SSH_INVALID_SOCKET && session->opts.host == NULL && session->opts.ProxyCommand == NULL) { diff --git a/src/pki_crypto.c b/src/pki_crypto.c index 4b6251ee..7494b162 100644 --- a/src/pki_crypto.c +++ b/src/pki_crypto.c @@ -637,11 +637,6 @@ ssh_string pki_private_key_to_pem(const ssh_key key, BIO *mem; int rc; - /* needed for openssl initialization */ - if (ssh_init() < 0) { - return NULL; - } - mem = BIO_new(BIO_s_mem()); if (mem == NULL) { return NULL; @@ -768,11 +763,6 @@ ssh_key pki_private_key_from_base64(const char *b64_key, void *ecdsa = NULL; #endif - /* needed for openssl initialization */ - if (ssh_init() < 0) { - return NULL; - } - type = pki_privatekey_type_from_string(b64_key); if (type == SSH_KEYTYPE_UNKNOWN) { SSH_LOG(SSH_LOG_WARN, "Unknown or invalid private key."); diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c index 4d6c2586..9f53321f 100644 --- a/src/pki_gcrypt.c +++ b/src/pki_gcrypt.c @@ -918,11 +918,6 @@ ssh_key pki_private_key_from_base64(const char *b64_key, enum ssh_keytypes_e type; int valid; - /* needed for gcrypt initialization */ - if (ssh_init() < 0) { - return NULL; - } - type = pki_privatekey_type_from_string(b64_key); if (type == SSH_KEYTYPE_UNKNOWN) { SSH_LOG(SSH_LOG_WARN, "Unknown or invalid private key."); diff --git a/src/pki_mbedcrypto.c b/src/pki_mbedcrypto.c index acef7ee1..3263db47 100644 --- a/src/pki_mbedcrypto.c +++ b/src/pki_mbedcrypto.c @@ -74,10 +74,6 @@ ssh_key pki_private_key_from_base64(const char *b64_key, const char *passphrase, size_t b64len = strlen(b64_key) + 1; unsigned char tmp[MAX_PASSPHRASE_SIZE] = {0}; - if (ssh_init() < 0) { - return NULL; - } - type = pki_privatekey_type_from_string(b64_key); if (type == SSH_KEYTYPE_UNKNOWN) { SSH_LOG(SSH_LOG_WARN, "Unknown or invalid private key."); diff --git a/tests/unittests/torture_threads_pki_rsa.c b/tests/unittests/torture_threads_pki_rsa.c index b26e56b5..2497583a 100644 --- a/tests/unittests/torture_threads_pki_rsa.c +++ b/tests/unittests/torture_threads_pki_rsa.c @@ -727,8 +727,14 @@ int torture_run_tests(void) * The original tests in torture_pki_rsa.c require files to be erased */ + /* + * If the library is statically linked, ssh_init() is not called + * automatically + */ + ssh_init(); torture_filter_tests(tests); rc = cmocka_run_group_tests(tests, NULL, NULL); + ssh_finalize(); return rc; }