[netdata] skip invalid TLVs in Network Data during iteration/search (#11283)

This commit enhances `NetworkData` modules to skip invalid TLVs during
iteration or search operations. Specifically, `NetworkDataTlv::Find
()` and `NetworkData::Iterate()` are updated. These two methods are
the primary methods used by all other methods for parsing or
searching for TLVs.

Generally, the leader validates TLVs before registration using
`NetworkData::Leader::Validate()`. However, this change improves
robustness by allowing receivers to also handle possible malformed
Network Data.

This commit also updates the `test_network_data` unit test to cover
the new behavior of skipping invalid TLVs.
This commit is contained in:
Abtin Keshavarzian
2025-02-24 08:55:34 -08:00
committed by GitHub
parent bc54d67ed8
commit 522f590fb6
4 changed files with 70 additions and 10 deletions
+23 -3
View File
@@ -117,9 +117,25 @@ void TestNetworkDataIterator(void)
VerifyOrQuit(instance != nullptr);
{
// Network Data:
// - An invalid TLV type.
// - An invalid Prefix TLV with prefix length of 129 (and two HasRoute sub-TLVs).
// - An invalid Prefix TLV with short length (length = 1)
// - An invalid Prefix TLV with no prefix.
// - A valid Prefix TLV with two HasRoute sub-TLVs
const uint8_t kNetworkData[] = {
0x08, 0x04, 0x0B, 0x02, 0x00, 0x00, 0x03, 0x14, 0x00, 0x40, 0xFD, 0x00, 0x12, 0x34,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC8, 0x00, 0x40, 0x01, 0x03, 0x54, 0x00, 0x00,
0xff, 0x03, 0x01, 0x02, 0x03,
0x03, 0x1D, 0x00, 0x81, 0xFD, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB,
0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x00, 0x03, 0xb8, 0x00, 0x40, 0x01, 0x03, 0x14, 0x00, 0x00,
0x03, 0x01, 0x00,
0x03, 0x02, 0x00, 0x40,
0x03, 0x14, 0x00, 0x40, 0xFD, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC8, 0x00,
0x40, 0x01, 0x03, 0x54, 0x00, 0x00,
};
otExternalRouteConfig routes[] = {
@@ -168,6 +184,8 @@ void TestNetworkDataIterator(void)
VerifyOrQuit(CompareExternalRouteConfig(rconfig, route));
}
VerifyOrQuit(netData.GetNextExternalRoute(iter, rconfig) == kErrorNotFound);
netData.FindRlocs(kAnyBrOrServer, kAnyRole, rlocs);
VerifyRlocsArray(rlocs, kRlocs);
@@ -667,7 +685,9 @@ void TestNetworkDataDsnSrpServices(void)
};
const uint8_t kNetworkData[] = {
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x28, 0x00,
0x0b, 0x01, 0x00,
0x0b, 0x0b, 0x80, 0x02, 0x5c, 0x02, 0x0d, 0x01, 0x00, 0x0d, 0x02, 0x28, 0x00,
0x0b, 0x09, 0x81, 0x02, 0x5c, 0xff, 0x0d, 0x03, 0x6c, 0x00, 0x05,