[tlvs] use uint32_t for TLV size to avoid overflows (#4216)

This commit is contained in:
Jonathan Hui
2019-10-01 08:36:39 -07:00
committed by GitHub
parent 86b3cfef56
commit 378183e21e
3 changed files with 9 additions and 5 deletions
+5 -1
View File
@@ -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)
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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.