From 5bb35892ddbe3b6fbadf29806ff62b4797a20a6e Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 26 May 2020 14:22:29 +0200 Subject: [PATCH] net: coap: Parse zero-length option correctly In case CoAP packet does not carry payload, and the last option is zero-length, the option structure was not filled with data (opt number and length). Fix the length check to prevent this from happening. Signed-off-by: Robert Lubos --- subsys/net/lib/coap/coap.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index 25aa1691638..a1c9c2f2f8c 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -493,11 +493,7 @@ static int parse_option(uint8_t *data, uint16_t offset, uint16_t *pos, return -EINVAL; } - if (r == 0) { - if (len == 0U) { - return r; - } - + if (r == 0 && len != 0U) { /* r == 0 means no more data to read from fragment, but len * field shows that packet should contain more data, it must * be a malformed packet.