From a998e32f95bce4b5ef9952771553a62c956a4e3b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 8 May 2012 01:02:18 +0900 Subject: [PATCH] Call ERR_clear_error() before OpenSSL I/O functions. Use ERR_get_error() with ERR_error_string(). --- src/SocketCore.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 823d302a..f619eb13 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -730,14 +730,14 @@ ssize_t SocketCore::writeData(const char* data, size_t len) } } else { #ifdef HAVE_OPENSSL + ERR_clear_error(); ret = SSL_write(ssl, data, len); if(ret < 0) { ret = sslHandleEAGAIN(ret); } if(ret < 0) { throw DL_RETRY_EX - (fmt(EX_SOCKET_SEND, - ERR_error_string(SSL_get_error(ssl, ret), 0))); + (fmt(EX_SOCKET_SEND, ERR_error_string(ERR_get_error(), 0))); } #endif // HAVE_OPENSSL #ifdef HAVE_LIBGNUTLS @@ -777,13 +777,14 @@ void SocketCore::readData(char* data, size_t& len) #ifdef HAVE_OPENSSL // for SSL // TODO handling len == 0 case required + ERR_clear_error(); ret = SSL_read(ssl, data, len); if(ret < 0) { ret = sslHandleEAGAIN(ret); } if(ret < 0) { throw DL_RETRY_EX - (fmt(EX_SOCKET_RECV, ERR_error_string(SSL_get_error(ssl, ret), 0))); + (fmt(EX_SOCKET_RECV, ERR_error_string(ERR_get_error(), 0))); } #endif // HAVE_OPENSSL #ifdef HAVE_LIBGNUTLS @@ -843,6 +844,7 @@ bool SocketCore::initiateSecureConnection(const std::string& hostname) wantRead_ = false; wantWrite_ = false; #ifdef HAVE_OPENSSL + ERR_clear_error(); int e = SSL_connect(ssl); if (e <= 0) {