Skip to content

Commit

Permalink
Fix BTLS OpenSSL BIO bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
m-ronnblom committed Jul 30, 2023
1 parent 30923b9 commit fb78c1c
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions libxcm/tp/tls/xcm_tp_btls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit fb78c1c

Please sign in to comment.