From e2dfed6035276993db2cde4784efebf5e9db0da6 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 25 Feb 2014 19:03:25 +0100 Subject: [PATCH] bugfix: #24 Empty ACK improperly includes Token Included the patch proposed by tbahls to fix this issue. Now, the ACK message is always truncated to its bare header when the message code is 0.00. --- net.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net.c b/net.c index 3fde4ad2..ea9ab0e7 100644 --- a/net.c +++ b/net.c @@ -1403,6 +1403,17 @@ handle_request(coap_context_t *context, coap_queue_t *node) { h(context, resource, &node->remote, node->pdu, &token, response); + /* If original request contained a token, and the registered + * application handler made no changes to the response, then + * this is an empty ACK with a token, which is a malformed + * PDU */ + if ((response->hdr->type == COAP_MESSAGE_ACK) + && (response->hdr->code == 0)) { + /* Remove token from otherwise-empty acknowledgment PDU */ + response->hdr->token_length = 0; + response->length = sizeof(coap_hdr_t); + } + if (response->hdr->type != COAP_MESSAGE_NON || (response->hdr->code >= 64 && !coap_is_mcast(&node->local))) {