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:
parent
0cf55c4174
commit
5bb35892dd
1 changed files with 1 additions and 5 deletions
|
@ -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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue