components/stunnel/patches/stunnel-4.56-CRYPTO_num_locks.patch
author Rich Burridge <rich.burridge@oracle.com>
Fri, 09 Aug 2013 12:58:20 -0700
branchs11-update
changeset 2723 138732f62341
permissions -rw-r--r--
17219320 Various Userland components should be back-ported to 11.2

# stunnel should use CRYPTO_num_locks() function instead of CRYPTO_NUM_LOCKS
# macro.  The function interogates libcrypto at run-time for sizing and the
# macro at compile time.  If you interpose a a version at runtime to switch
# between FIPS/non-FIPS support, the lock table may not be sized correctly.
#
diff -r -u stunnel-4.55.orig/src/sthreads.c stunnel-4.55/src/sthreads.c
--- stunnel-4.55.orig/src/sthreads.c	2012-08-09 14:44:18.000000000 -0700
+++ stunnel-4.55/src/sthreads.c	2013-03-21 23:29:34.912001586 -0700
@@ -212,7 +212,7 @@
 #ifdef USE_PTHREAD
 
 static pthread_mutex_t stunnel_cs[CRIT_SECTIONS];
-static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
+static pthread_mutex_t *lock_cs;
 
 void enter_critical_section(SECTION_CODE i) {
     pthread_mutex_lock(stunnel_cs+i);
@@ -275,13 +275,15 @@
 
 int sthreads_init(void) {
     int i;
+    int num_locks = CRYPTO_num_locks();
 
     /* initialize stunnel critical sections */
     for(i=0; i<CRIT_SECTIONS; i++)
         pthread_mutex_init(stunnel_cs+i, NULL);
 
     /* initialize OpenSSL locking callback */
-    for(i=0; i<CRYPTO_NUM_LOCKS; i++)
+    lock_cs = calloc(num_locks, sizeof (*lock_cs));
+    for(i=0; i<num_locks; i++)
         pthread_mutex_init(lock_cs+i, NULL);
     CRYPTO_set_id_callback(stunnel_thread_id);
     CRYPTO_set_locking_callback(locking_callback);