From aba0e4dc3f85c83fa3beb0d79d494857d83e25bf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 21 Dec 2014 21:08:28 +0000 Subject: SSL context double shutdown prevention git-svn-id: http://svn.miranda-ng.org/main/trunk@11567 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/netlib/netlib.cpp | 22 ++++++++++++---------- src/modules/netlib/netlibhttp.cpp | 3 ++- src/modules/netlib/netlibssl.cpp | 4 +--- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src/modules/netlib') diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp index 320876ff20..e6fe71ada1 100644 --- a/src/modules/netlib/netlib.cpp +++ b/src/modules/netlib/netlib.cpp @@ -279,7 +279,7 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM) HttpGatewayRemovePacket(nlc, -1); else { if (nlc->s != INVALID_SOCKET) - NetlibDoClose(nlc); + NetlibDoClose(nlc, nlc->termRequested); if (nlc->s2 != INVALID_SOCKET) closesocket(nlc->s2); nlc->s2 = INVALID_SOCKET; } @@ -389,18 +389,20 @@ INT_PTR NetlibShutdown(WPARAM wParam, LPARAM) switch(GetNetlibHandleType((void*)wParam)) { case NLH_CONNECTION: { - struct NetlibConnection* nlc = (struct NetlibConnection*)wParam; - if (nlc->hSsl) si.shutdown(nlc->hSsl); - if (nlc->s != INVALID_SOCKET) shutdown(nlc->s, 2); - if (nlc->s2 != INVALID_SOCKET) shutdown(nlc->s2, 2); - nlc->termRequested = true; + NetlibConnection *nlc = (NetlibConnection*)wParam; + if (!nlc->termRequested) { + if (nlc->hSsl) si.shutdown(nlc->hSsl); + if (nlc->s != INVALID_SOCKET) shutdown(nlc->s, 2); + if (nlc->s2 != INVALID_SOCKET) shutdown(nlc->s2, 2); + nlc->termRequested = true; + } } break; + case NLH_BOUNDPORT: - { - struct NetlibBoundPort* nlb = (struct NetlibBoundPort*)wParam; - if (nlb->s != INVALID_SOCKET) shutdown(nlb->s, 2); - } + struct NetlibBoundPort* nlb = (struct NetlibBoundPort*)wParam; + if (nlb->s != INVALID_SOCKET) + shutdown(nlb->s, 2); break; } ReleaseMutex(hConnectionHeaderMutex); diff --git a/src/modules/netlib/netlibhttp.cpp b/src/modules/netlib/netlibhttp.cpp index a42e9ea700..36514df345 100644 --- a/src/modules/netlib/netlibhttp.cpp +++ b/src/modules/netlib/netlibhttp.cpp @@ -122,7 +122,8 @@ static int RecvWithTimeoutTime(NetlibConnection *nlc, unsigned dwTimeoutTime, ch return NLRecv(nlc, buf, len, flags); } - if (nlc->termRequested || Miranda_Terminated()) return 0; + if (nlc->termRequested || Miranda_Terminated()) + return 0; } SetLastError(ERROR_TIMEOUT); return SOCKET_ERROR; diff --git a/src/modules/netlib/netlibssl.cpp b/src/modules/netlib/netlibssl.cpp index 3821c422a3..ccf0219e1f 100644 --- a/src/modules/netlib/netlibssl.cpp +++ b/src/modules/netlib/netlibssl.cpp @@ -357,9 +357,7 @@ static SECURITY_STATUS ClientHandshakeLoop(SslHandle *ssl, BOOL fDoInitialRead) if (scRet == SEC_E_OK) { // Store remaining data for further use if (InBuffers[1].BufferType == SECBUFFER_EXTRA) { - memmove(ssl->pbIoBuffer, - ssl->pbIoBuffer + (ssl->cbIoBuffer - InBuffers[1].cbBuffer), - InBuffers[1].cbBuffer); + memmove(ssl->pbIoBuffer, ssl->pbIoBuffer + (ssl->cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer); ssl->cbIoBuffer = InBuffers[1].cbBuffer; } else ssl->cbIoBuffer = 0; -- cgit v1.2.3