< Previous by Date Date Index Next by Date >
  Thread Index Next in Thread >

[reSIProcate] OpenSSLInit is not successfully ensuring the thread-safety of OpenSSL


Here's the offending code:

*snip*
#if !defined(WIN32) && defined(PTHREADS)
CRYPTO_set_id_callback(OpenSSLInit::threadIdFunction);
#endif
*snip*

There is no such preprocessor macro as "PTHREADS". The correct thing to be checking for here, AFAICT, is "_POSIX_THREADS". We should change this code to something like 

#if !defined(WIN32)
#if defined(_POSIX_THREADS)
CRYPTO_set_id_callback(OpenSSLInit::threadIdFunction);
#else
#error Can't set OpenSSL up to be threadsafe!
#endif
#endif

This assumes CRYPTO_thread_id() is set to something sensible by default on Windows; is this true Scott/Derek?

Also, this code would need to use _POSIX_THREADS

*snip*
unsigned long 
OpenSSLInit::threadIdFunction()
{
#if defined(WIN32)
   assert(0);
#else
#ifndef PTHREADS
   assert(0);
#endif
   unsigned long ret;
   ret= (unsigned long)pthread_self();
   return ret;
#endif
   return 0;
}
*snip*

Best regards,
Byron Campen