@@ -494,8 +494,12 @@ class SslFilter::Impl : private IOBuffer::Reader
494
494
}
495
495
if (inMaxRead == 0 ) {
496
496
// Don't want to read, just complete handshake.
497
- theRet = mSslEofFlag ? 0 :
498
- SSL_peek (mSslPtr , &theByte, sizeof (theByte));
497
+ if (mSslEofFlag ) {
498
+ theRet = 0 ;
499
+ } else {
500
+ ERR_clear_error ();
501
+ theRet = SSL_peek (mSslPtr , &theByte, sizeof (theByte));
502
+ }
499
503
mReadPendingFlag = 0 < theRet;
500
504
if (theRet < 0 ) {
501
505
theRet = SslRetToErr (theRet);
@@ -532,6 +536,7 @@ class SslFilter::Impl : private IOBuffer::Reader
532
536
if (inIoBuffer.IsEmpty ()) {
533
537
return 0 ;
534
538
}
539
+ ERR_clear_error ();
535
540
int theWrCnt = 0 ;
536
541
for (IOBuffer::iterator theIt = inIoBuffer.begin ();
537
542
theIt != inIoBuffer.end ();
@@ -560,8 +565,14 @@ class SslFilter::Impl : private IOBuffer::Reader
560
565
SslFilter& inOuter)
561
566
{
562
567
if (mSslPtr && inSocketPtr &&
563
- SSL_get_fd (mSslPtr ) == inSocketPtr->GetFd ()) {
564
- SSL_shutdown (mSslPtr );
568
+ SSL_get_fd (mSslPtr ) == inSocketPtr->GetFd () &&
569
+ SSL_is_init_finished (mSslPtr )) {
570
+ ERR_clear_error ();
571
+ const int theRet = SSL_shutdown (mSslPtr );
572
+ if (theRet <= 0 ) {
573
+ // Drain error queue.
574
+ SslRetToErr (theRet);
575
+ }
565
576
}
566
577
inConnection.SetFilter (0 , 0 );
567
578
if (mDeleteOnCloseFlag ) {
@@ -606,6 +617,7 @@ class SslFilter::Impl : private IOBuffer::Reader
606
617
mPeerPskId .clear ();
607
618
mServerFlag = ! SSL_in_connect_init (mSslPtr );
608
619
SetStoredClientSession ();
620
+ ERR_clear_error ();
609
621
const int theSslRet = mServerFlag ?
610
622
SSL_accept (mSslPtr ) : SSL_connect (mSslPtr );
611
623
if (theSslRet <= 0 ) {
@@ -655,6 +667,7 @@ class SslFilter::Impl : private IOBuffer::Reader
655
667
if (! inBufPtr || ! mSslPtr ) {
656
668
return -EINVAL;
657
669
}
670
+ ERR_clear_error ();
658
671
char * thePtr = reinterpret_cast <char *>(inBufPtr);
659
672
char * const theStartPtr = thePtr;
660
673
char * const theEndPtr = thePtr + inNumRead;
@@ -1042,6 +1055,7 @@ class SslFilter::Impl : private IOBuffer::Reader
1042
1055
mVerifyOrGetPskInvokedFlag = false ;
1043
1056
}
1044
1057
mRenegotiationPendingFlag = false ;
1058
+ ERR_clear_error ();
1045
1059
const int theRet = SSL_do_handshake (mSslPtr );
1046
1060
if (0 < theRet) {
1047
1061
if (! VerifyPeerIfNeeded ()) {
@@ -1197,6 +1211,7 @@ class SslFilter::Impl : private IOBuffer::Reader
1197
1211
// Wait for handshake to complete, then issue shutdown.
1198
1212
return 0 ;
1199
1213
}
1214
+ ERR_clear_error ();
1200
1215
int theRet = SSL_shutdown (mSslPtr );
1201
1216
if (theRet == 0 ) {
1202
1217
// Call shutdown again to initiate read state, if the shutdown call
0 commit comments