Fix unclean SSL disconnection

This patch prevent an infinite loop when the remote peer disconnect
the socket without cleanly closing the SSL connection.
This commit is contained in:
Hardening 2014-07-10 23:35:11 +02:00
parent 1a192f552b
commit 3fce288c66
2 changed files with 20 additions and 15 deletions

View File

@ -122,23 +122,28 @@ static int transport_bio_simple_read(BIO* bio, char* buf, int size)
BIO_clear_flags(bio, BIO_FLAGS_READ);
status = _recv((SOCKET) bio->num, buf, size, 0);
if (status > 0)
return status;
if (status <= 0)
if (status == 0)
{
error = WSAGetLastError();
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
(error == WSAEINPROGRESS) || (error == WSAEALREADY))
{
BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
}
else
{
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
}
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
return 0;
}
return status;
error = WSAGetLastError();
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
(error == WSAEINPROGRESS) || (error == WSAEALREADY))
{
BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
}
else
{
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
}
return -1;
}
static int transport_bio_simple_puts(BIO* bio, const char* str)
@ -327,7 +332,6 @@ static int transport_bio_buffered_read(BIO* bio, char* buf, int size)
if (!BIO_should_retry(bio->next_bio))
{
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
status = -1;
goto out;
}

View File

@ -152,7 +152,8 @@ static int bio_rdp_tls_read(BIO* bio, char* buf, int size)
break;
case SSL_ERROR_SYSCALL:
status = 0;
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
status = -1;
break;
}
}