Issue 1823 - Problem with TLS: threads and OpenSSL
Summary: Problem with TLS: threads and OpenSSL
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: slapd (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-16 11:57 UTC by raimo.vuonnala@nokia.com
Modified: 2020-03-20 14:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description raimo.vuonnala@nokia.com 2002-05-16 11:57:21 UTC
Full_Name: Raimo Vuonnala
Version: 2.0.23
OS: 
URL: 
Submission from: (NULL) (192.100.124.218)


Hi,

While wondering why my multithreaded app in Win2000 did not work
correctly, I discovered the following problems in libraries/libldap/tls.c:


1. tls_init_threads() sets OpenSSL crypto locks although someone else has
   already set them. I would recommend to fix this as follows:
  
   static void tls_init_threads( void )
   {
        int i;

        ldap_pvt_thread_mutex_init( &tls_def_ctx_mutex );

        if (!CRYPTO_get_locking_callback()) {
          for( i=0; i< CRYPTO_NUM_LOCKS ; i++ ) {
                ldap_pvt_thread_mutex_init( &tls_mutexes[i] );
          }
          CRYPTO_set_locking_callback( tls_locking_cb );
          /* FIXME: the thread id should be added somehow... */
        }
  }


2. ldap_pvt_tls_init(): several threads can call tsl_init_thread().
   The following fix will prevent this:

   int
   ldap_pvt_tls_init( void )
   {
        static volatile int tls_initialized = 0;

   #ifdef LDAP_R_COMPILE
        if ( tls_initialized == 1) return 0;
        while (tls_initialized == -1)
          ldap_pvt_thread_yield();
        tls_initialized = -1;
        tls_init_threads();
   #else
        if ( tls_initialized ) return 0;
   #endif

        (void) tls_seed_PRNG( tls_opt_randfile );

        SSL_load_error_strings();
        SSLeay_add_ssl_algorithms();

        /* FIXME: mod_ssl does this */
        X509V3_add_standard_extensions();
        tls_initialized = 1;
        return 0;
  }


Best Regards
Raimo Vuonnala




Comment 1 Kurt Zeilenga 2002-06-02 00:57:04 UTC
changed notes
changed state Open to Closed
Comment 2 Howard Chu 2004-12-06 01:32:50 UTC
moved from Incoming to Archive.Incoming
Comment 3 OpenLDAP project 2014-08-01 21:05:39 UTC
library does support current session allocation.