From 50b97074e860c6d0df43deec7886f661c2854c13 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 10 Feb 2018 03:36:43 +0600 Subject: [PATCH] coap_openssl.c: client assert error if DTLS error closed socket For a client, if a DTLS session is closed with ICMP unavailable packet, when the TLS session is closed in the application with SSL_shutdown(), the OpenSSL underlying library triggers a BIO_write() which calls coap_dgram_write() which then 'assert's in coap_session_send(). (sock->flags == COAP_SOCKET_EMPTY && session->endpoint == NULL). Fix is not to call coap_session_send() from coap_dgram_write() if socket is closed and this is not an endpoint (not a server). --- src/coap_openssl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coap_openssl.c b/src/coap_openssl.c index 998ac7c1..c6fb1643 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -123,6 +123,11 @@ static int coap_dgram_write(BIO *a, const char *in, int inl) { coap_ssl_data *data = (coap_ssl_data *)BIO_get_data(a); if (data->session) { + if (data->session->sock.flags == COAP_SOCKET_EMPTY && data->session->endpoint == NULL) { + /* socket was closed on client due to error */ + BIO_clear_retry_flags(a); + return -1; + } ret = (int)coap_session_send(data->session, (unsigned char*)in, (size_t)inl); BIO_clear_retry_flags(a); if (ret <= 0)