From 05195ab464f5911fb193e921e75fabd43041aeba Mon Sep 17 00:00:00 2001 From: XieHan Date: Mon, 12 Jul 2021 23:14:37 +0800 Subject: [PATCH] fix SSLWrapper feedback --- src/protocol/SSLWrapper.cc | 61 +++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/protocol/SSLWrapper.cc b/src/protocol/SSLWrapper.cc index 0f489e18..b30af331 100644 --- a/src/protocol/SSLWrapper.cc +++ b/src/protocol/SSLWrapper.cc @@ -235,29 +235,6 @@ int SSLWrapper::append(const void *buf, size_t *size) return this->append_message(); } -int ServiceSSLWrapper::append(const void *buf, size_t *size) -{ - char *ptr; - long len; - long n; - - if (__ssl_handshake(buf, size, this->ssl, &ptr, &len) < 0) - return -1; - - if (len > 0) - n = this->feedback(ptr, len); - else - n = 0; - - if (n == len) - return this->append_message(); - - if (n >= 0) - errno = EAGAIN; - - return -1; -} - int SSLWrapper::feedback(const void *buf, size_t size) { BIO *wbio = SSL_get_wbio(this->ssl); @@ -282,12 +259,40 @@ int SSLWrapper::feedback(const void *buf, size_t size) } len = BIO_get_mem_data(wbio, &ptr); - if (len > 0) - return this->ProtocolWrapper::feedback(ptr, len); - else if (len == 0) - return 0; - else + if (len >= 0) + { + ret = this->ProtocolWrapper::feedback(ptr, len); + if (ret == len) + return size; + + if (ret > 0) + errno = ENOBUFS; + } + + return -1; +} + +int ServiceSSLWrapper::append(const void *buf, size_t *size) +{ + char *ptr; + long len; + long n; + + if (__ssl_handshake(buf, size, this->ssl, &ptr, &len) < 0) return -1; + + if (len > 0) + n = this->feedback(ptr, len); + else + n = 0; + + if (n == len) + return this->append_message(); + + if (n >= 0) + errno = EAGAIN; + + return -1; } }