Richard Levitte - VMS Whacker wrote:
>
> From: Gleb Esman <[EMAIL PROTECTED]>
>
>
> gesman> // Cleanup and exit.
> gesman> if (pSsl) SSL_shutdown (pSsl);
> gesman>
> gesman> iRetCode = shutdown (sSocket, SD_BOTH);
> gesman> closesocket (sSocket);
> gesman> if (pSsl) SSL_free (pSsl);
>
> THAT sequence gives me the creaps (sp?). You see, the fd's you
> declared earlier with SSL_set_fd() got "registered" in the SSL
> structure through a couple of BIOs. SSL_free() will fo a
> BIO_free_all() on those, and BIO_free_all() will most definitely try
> to close the socket... that you already closed and shut down and
> everything. I can understand the need to do a shutdown() and
> closesocket() yourself, but in that case you have to tell the BIOs
> that they should not close the fd, like this:
>
> BIO_set_close(SSL_get_rbio(pSsl,BIO_NOCLOSE);
> BIO_set_close(SSL_get_wbio(pSsl,BIO_NOCLOSE);
>
> At least, that's what I understand of the whole thing (I've got pretty
> slim knowlege of the SSL part of OpenSSL, but am learning fast right
> now...).
>
Yes indeed that is a recipe for disaster. One possible scenario:
Most of the time BIO_free() will close the socket and close() will close
an invalid fd: that's an error but otherwise harmless.
Occasionally BIO_free() will close the socket and another thread will
get a look in. Since the fd value is now "available" another thread can
get the same value. As a result the second close() will close a
perfectly valid fd which belongs to another thread. The result is chaos
in the other thread.
Steve.
--
Dr Stephen N. Henson. http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED]
Senior crypto Engineer, Celo Communications: http://www.celocom.com/
Core developer of the OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]