mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 05:49:54 +00:00
[tlvs] use uint32_t for TLV size to avoid overflows (#4216)
This commit is contained in:
@@ -404,7 +404,11 @@ exit:
|
||||
|
||||
otError Message::AppendTlv(const Tlv &aTlv)
|
||||
{
|
||||
return Append(&aTlv, aTlv.GetSize());
|
||||
uint32_t size = aTlv.GetSize();
|
||||
|
||||
assert(size <= UINT16_MAX);
|
||||
|
||||
return Append(&aTlv, static_cast<uint16_t>(size));
|
||||
}
|
||||
|
||||
otError Message::Prepend(const void *aBuf, uint16_t aLength)
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
uint16_t Tlv::GetSize(void) const
|
||||
uint32_t Tlv::GetSize(void) const
|
||||
{
|
||||
return IsExtended() ? sizeof(ExtendedTlv) + static_cast<const ExtendedTlv *>(this)->GetLength()
|
||||
: sizeof(Tlv) + GetLength();
|
||||
@@ -108,7 +108,7 @@ otError Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uin
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
uint16_t remainingLen = aMessage.GetLength();
|
||||
Tlv tlv;
|
||||
uint16_t size;
|
||||
uint32_t size;
|
||||
|
||||
VerifyOrExit(offset <= remainingLen);
|
||||
remainingLen -= offset;
|
||||
@@ -144,7 +144,7 @@ otError Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uin
|
||||
|
||||
if (aSize != NULL)
|
||||
{
|
||||
*aSize = size;
|
||||
*aSize = static_cast<uint16_t>(size);
|
||||
}
|
||||
|
||||
if (aIsExtendedTlv != NULL)
|
||||
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
* @returns The total size include Type, Length, and Value fields.
|
||||
*
|
||||
*/
|
||||
uint16_t GetSize(void) const;
|
||||
uint32_t GetSize(void) const;
|
||||
|
||||
/**
|
||||
* This method returns a pointer to the Value.
|
||||
|
||||
Reference in New Issue
Block a user