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 <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2020-05-26 14:22:29 +02:00 committed by Jukka Rissanen
commit 5bb35892dd

View file

@ -493,11 +493,7 @@ static int parse_option(uint8_t *data, uint16_t offset, uint16_t *pos,
return -EINVAL; return -EINVAL;
} }
if (r == 0) { if (r == 0 && len != 0U) {
if (len == 0U) {
return r;
}
/* r == 0 means no more data to read from fragment, but len /* r == 0 means no more data to read from fragment, but len
* field shows that packet should contain more data, it must * field shows that packet should contain more data, it must
* be a malformed packet. * be a malformed packet.