From 440b645a1583a39e2f44a782bf1bd0a143b2b7a6 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Fri, 14 Mar 2025 10:49:35 +0000 Subject: [PATCH] coap_openssl.c: Clear thread errors before doing read/write for TLS When using multi-threads, if a thread does i/o, but previously that thread had an SSL error which has not been properly cleared, then the read or write will fail with SSL_ERROR_SSL. Make sure that there are no errors before doing SSL_read() or SSL_write(). --- src/coap_openssl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coap_openssl.c b/src/coap_openssl.c index f1e9f4d3..e1aa0ab5 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -3932,6 +3932,7 @@ coap_tls_write(coap_session_t *session, const uint8_t *data, size_t data_len) { in_init = !SSL_is_init_finished(ssl); session->dtls_event = -1; + ERR_clear_error(); r = SSL_write(ssl, data, (int)data_len); if (r <= 0) { @@ -4011,6 +4012,7 @@ coap_tls_read(coap_session_t *session, uint8_t *data, size_t data_len) { in_init = !SSL_is_init_finished(ssl); session->dtls_event = -1; + ERR_clear_error(); r = SSL_read(ssl, data, (int)data_len); if (r <= 0) { int err = SSL_get_error(ssl, r);