Re: PKCS12_parse() in multi-threads, heap is corrupt
On Sun, Dec 11, 2011, cellecial wrote: Hi, I wrote a simple pkcs12 demo(under Windows), it just read from a PKCS12 file and got private key and certificate. If I use single thread, it works fine. If I use multi-thread, it works fine for a while ,then popups an error dialogue heap is corrupt.If I debug it in Visual Studio,it points to PKCS12_parse() . If I use EnterCriticalSection and LeaveCriticalSection with multi-thread, it works fine too, but as you know, the effect is as same as single thread does. So I want to know , what shared resource is protected by CriticalSection? Is PKCS12_parse() not thread-safe? Can it be executed in multi-threads without mutex? int pkcs12test(unsigned char *p12buf, int p12buflen, unsigned char *p12pswd) { PKCS12 *p12; X509 *cert; EVP_PKEY *prvkey; int len; char buf[4096]; int i=0; char desc[1000]; OpenSSL_add_all_algorithms(); At least one problem is the above line. You should call OpenSSL_add_all_algorithm() *once* before starting threads. Steve. -- Dr Stephen N. Henson. OpenSSL project core developer. Commercial tech support now available see: http://www.openssl.org __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager majord...@openssl.org
Re: PKCS12_parse() in multi-threads, heap is corrupt
Thank you. I add OpenSSL_add_all_algorithms(); in main function and include openssl/evp.h,but it still pops error dialogue after a while. Some threads can end well, others are not so lucky. On Sun, Dec 11, 2011 at 8:14 PM, Dr. Stephen Henson st...@openssl.orgwrote: On Sun, Dec 11, 2011, cellecial wrote: Hi, I wrote a simple pkcs12 demo(under Windows), it just read from a PKCS12 file and got private key and certificate. If I use single thread, it works fine. If I use multi-thread, it works fine for a while ,then popups an error dialogue heap is corrupt.If I debug it in Visual Studio,it points to PKCS12_parse() . If I use EnterCriticalSection and LeaveCriticalSection with multi-thread, it works fine too, but as you know, the effect is as same as single thread does. So I want to know , what shared resource is protected by CriticalSection? Is PKCS12_parse() not thread-safe? Can it be executed in multi-threads without mutex? int pkcs12test(unsigned char *p12buf, int p12buflen, unsigned char *p12pswd) { PKCS12 *p12; X509 *cert; EVP_PKEY *prvkey; int len; char buf[4096]; int i=0; char desc[1000]; OpenSSL_add_all_algorithms(); At least one problem is the above line. You should call OpenSSL_add_all_algorithm() *once* before starting threads. Steve. -- Dr Stephen N. Henson. OpenSSL project core developer. Commercial tech support now available see: http://www.openssl.org __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager majord...@openssl.org
Re: PKCS12_parse() in multi-threads, heap is corrupt
On Sun, Dec 11, 2011, cellecial wrote: Thank you. I add OpenSSL_add_all_algorithms(); in main function and include openssl/evp.h,but it still pops error dialogue after a while. Some threads can end well, others are not so lucky. Have you set the locking callbacks? You need to set those to make OpenSSL thread safe. See the FAQ and documentation for more details. Steve. -- Dr Stephen N. Henson. OpenSSL project core developer. Commercial tech support now available see: http://www.openssl.org __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager majord...@openssl.org
Re: PKCS12_parse() in multi-threads, heap is corrupt
Thank you and sorry for my last two posts without reading FAQ carefully first. Now I read FAQ and the example of the call functions. It seems I need more time to understand it and do some examples by myself. Anywise I should complete my work asap, so I add thread_setup() and thread_cleanup() and win32_locking_callback() to my code,It still fails in multi-thread mode. I think may be my openssl wasn't configured with thread support , but Configure instruction said, *# [no-]threads [don't] try to create a library that is suitable for # multithreaded applications (default is threads if we # know how to do it)* I guess that means openssl on windows is supporting thread defaultly. And I found snippet in opensslconf.h *#ifndef OPENSSL_THREADS # define OPENSSL_THREADS #endif *It seems like switching on the thread support. Is there anything I can do to make it work? On Sun, Dec 11, 2011 at 8:51 PM, Dr. Stephen Henson st...@openssl.orgwrote: On Sun, Dec 11, 2011, cellecial wrote: Thank you. I add OpenSSL_add_all_algorithms(); in main function and include openssl/evp.h,but it still pops error dialogue after a while. Some threads can end well, others are not so lucky. Have you set the locking callbacks? You need to set those to make OpenSSL thread safe. See the FAQ and documentation for more details. Steve. -- Dr Stephen N. Henson. OpenSSL project core developer. Commercial tech support now available see: http://www.openssl.org __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager majord...@openssl.org