Reject CoAP frames with a reserved or truncated token length


RFC 7252 §3 reserves token lengths 9-15 and requires treating them as
a message format error but the parser accepted them and mis-parsed the
frame. With a large reserved value the bytes that follow are swallowed
as the token and the remainder is parsed as options from the wrong
offset.

A valid token length could likewise claim more bytes than were
actually sent, producing a silently truncated token.

Neither is a crash now that the option loop is bounds-checked, but the
token is the key used to match a reply to its request, so a mis-parsed
or truncated token is an integrity problem. Reject both: a token length
greater than 8, and a token whose bytes do not all fit in the frame.

Task-number: QTBUG-149345
Pick-to: 6.12 6.11 6.8
Change-Id: I301bed8aa9aa1e17faf43dd7aa6ad0d85fc83cd3
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
commit1a369fc74f05b22db37f4021eec382c8c1aad84f
parent98f07776a22c6eb463ad6695f215a9cc0b86a1e5
authorMate Barany <mate.barany@qt.io>
committerMate Barany <mate.barany@qt.io>
commit timeTue, 1 Sep 2026 17:07:23 +0000