From 95faeac5bb1f3ac6e1b6bef4190eab4d3a7309eb Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Wed, 18 Oct 2023 13:40:43 +0100 Subject: [PATCH] pdu: Make sure type is set to CON if Reliable --- src/coap_net.c | 2 +- src/coap_pdu.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coap_net.c b/src/coap_net.c index fcf9b7ff..2f2406ac 100644 --- a/src/coap_net.c +++ b/src/coap_net.c @@ -1096,7 +1096,7 @@ coap_send(coap_session_t *session, coap_pdu_t *pdu) { } /* A lot of the reliable code assumes type is CON */ - if (COAP_PROTO_RELIABLE(session->proto) && pdu->type == COAP_MESSAGE_NON) + if (COAP_PROTO_RELIABLE(session->proto) && pdu->type != COAP_MESSAGE_CON) pdu->type = COAP_MESSAGE_CON; #if COAP_OSCORE_SUPPORT diff --git a/src/coap_pdu.c b/src/coap_pdu.c index afe445c8..56cb55b6 100644 --- a/src/coap_pdu.c +++ b/src/coap_pdu.c @@ -1435,6 +1435,11 @@ coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) { coap_log_warn("coap_pdu_encode_header: corrupted PDU\n"); return 0; } + + /* A lot of the reliable code assumes type is CON */ + if (pdu->type != COAP_MESSAGE_CON) + pdu->type = COAP_MESSAGE_CON; + if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) len = 0; else