libssh/0001-threads-Use-new-API-call-for-OpenSSL-CRYPTO-THREADID.patch

81 lines
2.9 KiB
Diff
Raw Normal View History

From 2dff359a331c5c9aab2435c470596b0fee7a502a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Sun, 6 Nov 2016 12:07:32 +0100
Subject: [PATCH] threads: Use new API call for OpenSSL CRYPTO THREADID
BUG: https://red.libssh.org/issues/222
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
---
ConfigureChecks.cmake | 3 +++
config.h.cmake | 3 +++
src/threads.c | 19 +++++++++++++++++--
3 files changed, 23 insertions(+), 2 deletions(-)
Index: libssh-0.7.5/ConfigureChecks.cmake
===================================================================
--- libssh-0.7.5.orig/ConfigureChecks.cmake 2017-08-22 09:52:57.756607716 +0200
+++ libssh-0.7.5/ConfigureChecks.cmake 2017-08-22 09:53:16.480897731 +0200
@@ -91,6 +91,10 @@ if (OPENSSL_FOUND)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
check_include_file(openssl/ecdsa.h HAVE_OPENSSL_ECDSA_H)
+
+ set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
+ set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
+ check_function_exists(CRYPTO_THREADID_set_callback HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK)
endif()
if (CMAKE_HAVE_PTHREAD_H)
Index: libssh-0.7.5/config.h.cmake
===================================================================
--- libssh-0.7.5.orig/config.h.cmake 2017-08-22 09:52:41.940362760 +0200
+++ libssh-0.7.5/config.h.cmake 2017-08-22 09:52:57.756607716 +0200
@@ -76,6 +76,9 @@
/*************************** FUNCTIONS ***************************/
+/* Define to 1 if you have the `CRYPTO_THREADID_set_callback' function. */
+#cmakedefine HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK 1
+
/* Define to 1 if you have the `snprintf' function. */
#cmakedefine HAVE_SNPRINTF 1
Index: libssh-0.7.5/src/threads.c
===================================================================
--- libssh-0.7.5.orig/src/threads.c 2017-08-22 09:52:41.944362821 +0200
+++ libssh-0.7.5/src/threads.c 2017-08-22 09:52:57.756607716 +0200
@@ -116,6 +116,15 @@ static void libcrypto_lock_callback(int
}
}
+#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK
+static void libcrypto_THREADID_callback(CRYPTO_THREADID *id)
+{
+ unsigned long thread_id = (*user_callbacks->thread_id)();
+
+ CRYPTO_THREADID_set_numeric(id, thread_id);
+}
+#endif /* HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK */
+
static int libcrypto_thread_init(void){
int n=CRYPTO_num_locks();
int i;
@@ -127,8 +136,14 @@ static int libcrypto_thread_init(void){
for (i=0;i<n;++i){
user_callbacks->mutex_init(&libcrypto_mutexes[i]);
}
- CRYPTO_set_id_callback(user_callbacks->thread_id);
- CRYPTO_set_locking_callback(libcrypto_lock_callback);
+
+#ifdef HAVE_OPENSSL_CRYPTO_THREADID_SET_CALLBACK
+ CRYPTO_THREADID_set_callback(libcrypto_THREADID_callback);
+#else
+ CRYPTO_set_id_callback(user_callbacks->thread_id);
+#endif
+
+ CRYPTO_set_locking_callback(libcrypto_lock_callback);
return SSH_OK;
}