From 0b7d1d8644d68097b8bf51a4e0e5b20e7f7e2ff2 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 12 Feb 2018 15:44:12 +0000 Subject: [PATCH] coap_io.c: Prevent coap_write() blowing up if opaque tls is not set When determing whether to do a re-transmit timeout based on coap_dtls_get_timeout, if s->tls is not set (unable to set up TLS session, TLS error etc.), then coap_write() assert's when calling coap_dtls_get_timeout(). This fix just sets the timeout to 0 if s->tls is not set. --- src/coap_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coap_io.c b/src/coap_io.c index 9af6d98e..8277ec70 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -1094,9 +1094,9 @@ coap_write(coap_context_t *ctx, if (s->proto == COAP_PROTO_DTLS && s->tls) { coap_tick_t tls_timeout = coap_dtls_get_timeout(s); while (tls_timeout > 0 && tls_timeout <= now) { - debug("** %s: DTLS retransmit timeout\n", coap_session_str(s)); + coap_log(LOG_DEBUG, "** %s: DTLS retransmit timeout\n", coap_session_str(s)); coap_dtls_handle_timeout(s); - tls_timeout = coap_dtls_get_timeout(s); + tls_timeout = s->tls ? coap_dtls_get_timeout(s) : 0; } if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout)) timeout = tls_timeout - now; @@ -1108,9 +1108,9 @@ coap_write(coap_context_t *ctx, if (s->proto == COAP_PROTO_DTLS && s->tls) { coap_tick_t tls_timeout = coap_dtls_get_timeout(s); while (tls_timeout > 0 && tls_timeout <= now) { - debug("** %s: DTLS retransmit timeout\n", coap_session_str(s)); + coap_log(LOG_DEBUG, "** %s: DTLS retransmit timeout\n", coap_session_str(s)); coap_dtls_handle_timeout(s); - tls_timeout = coap_dtls_get_timeout(s); + tls_timeout = s->tls ? coap_dtls_get_timeout(s) : 0; } if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout)) timeout = tls_timeout - now;