[network-data] add length validation to Service TLV (#2527)

Credit to OSS-Fuzz.
This commit is contained in:
Jonathan Hui
2018-02-02 17:03:36 +00:00
committed by GitHub
parent 639b58eae7
commit 1318d7942e
2 changed files with 20 additions and 2 deletions
@@ -528,6 +528,7 @@ otError Leader::RlocLookup(uint16_t aRloc16, bool &aIn, bool &aStable, uint8_t *
case NetworkDataTlv::kTypeService:
{
service = static_cast<ServiceTlv *>(cur);
VerifyOrExit(service->IsValid(), error = OT_ERROR_PARSE);
subCur = service->GetSubTlvs();
subEnd = service->GetNext();
+19 -2
View File
@@ -297,8 +297,8 @@ public:
*
*/
bool IsValid(void) const {
return ((GetLength() >= sizeof(*this) - sizeof(Tlv)) &&
(GetLength() >= BitVectorBytes(mPrefixLength) + sizeof(*this) - sizeof(Tlv)));
return ((GetLength() >= sizeof(*this) - sizeof(NetworkDataTlv)) &&
(GetLength() >= BitVectorBytes(mPrefixLength) + sizeof(*this) - sizeof(NetworkDataTlv)));
}
/**
@@ -712,6 +712,23 @@ public:
*/
void Init(void) { NetworkDataTlv::Init(); SetType(kTypeService); SetLength(2); mTResSId = kTMask; SetServiceDataLength(0); }
/**
* This method indicates whether or not the TLV appears to be well-formed.
*
* @retval TRUE If the TLV appears to be well-formed.
* @retval FALSE If the TLV does not appear to be well-formed.
*
*/
bool IsValid(void) {
uint8_t length = GetLength();
return ((length >= (sizeof(*this) - sizeof(NetworkDataTlv))) &&
(length >= ((sizeof(*this) - sizeof(NetworkDataTlv)) +
(IsThreadEnterprise() ? 0 : sizeof(uint32_t)) + sizeof(uint8_t))) &&
(length >= ((sizeof(*this) - sizeof(NetworkDataTlv)) +
(IsThreadEnterprise() ? 0 : sizeof(uint32_t)) + sizeof(uint8_t) +
GetServiceDataLength())));
}
/**
* This method gets Service Data length.
*