mirror of
https://github.com/espressif/openthread.git
synced 2026-08-07 03:07:47 +00:00
[history] parse TLV headers safely in client answer processing (#13410)
This commit updates `HistoryTracker::Client::ProcessNetInfoAnswer()` to iterate over answer TLVs using `Tlv::Info::ParseFrom()`, which reads the full TLV header, including any extended-length field, and validates that the entire TLV is contained within the remaining offset range. Extended TLVs are skipped, since all answer TLVs the client consumes are non-extended.
This commit is contained in:
@@ -163,23 +163,27 @@ void Client::ProcessNetInfoAnswer(const Coap::Message &aMessage)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
OffsetRange offsetRange;
|
||||
Tlv tlv;
|
||||
Tlv::Info tlvInfo;
|
||||
NetworkInfoTlv netInfoTlv;
|
||||
NetworkInfo netInfo;
|
||||
|
||||
offsetRange.InitFromMessageOffsetToEnd(aMessage);
|
||||
|
||||
for (; !offsetRange.IsEmpty(); offsetRange.AdvanceOffset(tlv.GetSize()))
|
||||
for (; !offsetRange.IsEmpty(); offsetRange.AdvanceOffset(tlvInfo.GetSize()))
|
||||
{
|
||||
SuccessOrExit(error = aMessage.Read(offsetRange, tlv));
|
||||
VerifyOrExit(offsetRange.Contains(tlv.GetSize()), error = kErrorParse);
|
||||
SuccessOrExit(error = tlvInfo.ParseFrom(aMessage, offsetRange));
|
||||
|
||||
if (tlv.GetType() != Tlv::kNetworkInfo)
|
||||
if (tlvInfo.IsExtended())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tlv.GetLength() == 0)
|
||||
if (tlvInfo.GetType() != Tlv::kNetworkInfo)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tlvInfo.GetLength() == 0)
|
||||
{
|
||||
Finalize(kErrorNone);
|
||||
ExitNow();
|
||||
|
||||
Reference in New Issue
Block a user