From fb78c1c3402fe3732af9c36e6a6fb8d0a4e1dd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Date: Mon, 31 Jul 2023 01:43:22 +0200 Subject: [PATCH] Fix BTLS OpenSSL BIO bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix bug in BTLS custom OpenSSL BIO which caused SSL_write() to ask the caller to wait for the BIO to become readable, when in fact it needed more BIO output buffer space to finish the requested operation, and thus should ask for the caller to wait for the BIO to become writable. This bug was introduced when BTLS was moved over from "raw" BSD sockets to using BTCP (commit fb881f2), and was never present in any released version of XCM. This patch reverts the changes introduced by 30923b9, which wasn't addressing the root cause. Signed-off-by: Mattias Rönnblom --- libxcm/tp/tls/xcm_tp_btls.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libxcm/tp/tls/xcm_tp_btls.c b/libxcm/tp/tls/xcm_tp_btls.c index e9cba4799..11a94e0d8 100644 --- a/libxcm/tp/tls/xcm_tp_btls.c +++ b/libxcm/tp/tls/xcm_tp_btls.c @@ -190,7 +190,7 @@ static int bio_btcp_write(BIO *b, const char *buf, int len) if (rc < 0) { if (errno == EAGAIN) - BIO_set_retry_read(b); + BIO_set_retry_write(b); else if (errno == EPIPE) BIO_set_flags(b, BIO_get_flags(b) | BIO_FLAGS_IN_EOF); } @@ -1116,15 +1116,7 @@ static void conn_update(struct xcm_socket *s) if (s->condition == 0) break; else if (s->condition&XCM_SO_RECEIVABLE && - SSL_pending(bts->conn.ssl) > 0) - ready = true; - else if (SSL_pending(bts->conn.ssl) == 0 && SSL_has_pending(bts->conn.ssl)) - /* Unprocessed data (a result of OpenSSL read-ahead) may - lead to SSL_WANTS_READ even at SSL_write(), - seemingly. This in turn may lead to a dead lock, so - it's better to turn this into processed data even - though application isn't waiting for XCM_SO_RECEIVABLE. */ ready = true; else if (bts->conn.ssl_condition == 0) /* No SSL_read()/write() issued */