Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 2cf08e8

Browse files
author
Jay Logue
authored
Merge pull request #579 from openweave/feature/emargolis/relax-path-check-in-verify-element
Relax Check for TLV Path Element in the VerifyElement().
2 parents 1f9b540 + 536ad51 commit 2cf08e8

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

src/lib/core/WeaveTLVReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,6 @@ WEAVE_ERROR TLVReader::VerifyElement()
13821382
return WEAVE_ERROR_INVALID_TLV_TAG;
13831383
break;
13841384
case kTLVType_Structure:
1385-
case kTLVType_Path:
13861385
if (mElemTag == AnonymousTag)
13871386
return WEAVE_ERROR_INVALID_TLV_TAG;
13881387
break;
@@ -1391,6 +1390,7 @@ WEAVE_ERROR TLVReader::VerifyElement()
13911390
return WEAVE_ERROR_INVALID_TLV_TAG;
13921391
break;
13931392
case kTLVType_UnknownContainer:
1393+
case kTLVType_Path:
13941394
break;
13951395
default:
13961396
return WEAVE_ERROR_INCORRECT_STATE;

src/lib/core/WeaveTLVWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ WEAVE_ERROR TLVWriter::WriteElementHead(TLVElementType elemType, uint64_t tag, u
16801680
else
16811681
{
16821682
if (elemType != kTLVElementType_EndOfContainer && mContainerType != kTLVType_NotSpecified
1683-
&& mContainerType != kTLVType_Array)
1683+
&& mContainerType != kTLVType_Array && mContainerType != kTLVType_Path)
16841684
return WEAVE_ERROR_INVALID_TLV_TAG;
16851685

16861686
Write8(p, kTLVTagControl_Anonymous | elemType);

src/test-apps/TestTLV.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -283,28 +283,27 @@ static const uint8_t Encoding1[] =
283283
0xD5, 0xBB, 0xAA, 0xDD, 0xCC, 0x01, 0x00, 0xC9, 0xBB, 0xAA, 0xDD, 0xCC, 0x02, 0x00, 0x88, 0x02,
284284
0x00, 0x36, 0x00, 0x00, 0x2A, 0x00, 0xEF, 0x02, 0xF0, 0x67, 0xFD, 0xFF, 0x07, 0x00, 0x90, 0x2F,
285285
0x50, 0x09, 0x00, 0x00, 0x00, 0x15, 0x18, 0x17, 0xD4, 0xBB, 0xAA, 0xDD, 0xCC, 0x11, 0x00, 0xB4,
286-
0xA0, 0xBB, 0x0D, 0x00, 0xB5, 0x00, 0x28, 0x6B, 0xEE, 0x6D, 0x70, 0x11, 0x01, 0x00, 0x0E, 0x01,
287-
0x53, 0x54, 0x41, 0x52, 0x54, 0x2E, 0x2E, 0x2E, 0x21, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
288-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x40, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
289-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x23, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
290-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x24, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
291-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x25, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
292-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x5E, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
293-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x26, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
294-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x2A, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
295-
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
296-
0x28, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
297-
0x29, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
298-
0x2D, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
299-
0x3D, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
300-
0x5B, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
301-
0x5D, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
302-
0x3B, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
303-
0x27, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x2E, 0x2E, 0x2E, 0x45, 0x4E, 0x44, 0x18, 0x18,
304-
0x18, 0xCC, 0xBB, 0xAA, 0xDD, 0xCC, 0x05, 0x00, 0x0E, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73,
305-
0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74,
306-
0x8A, 0xFF, 0xFF, 0x33, 0x33, 0x8f, 0x41,
307-
0xAB, 0x00, 0x00, 0x01, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x31, 0x40, 0x18
286+
0xA0, 0xBB, 0x0D, 0x00, 0x14, 0xB5, 0x00, 0x28, 0x6B, 0xEE, 0x6D, 0x70, 0x11, 0x01, 0x00, 0x0E,
287+
0x01, 0x53, 0x54, 0x41, 0x52, 0x54, 0x2E, 0x2E, 0x2E, 0x21, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
288+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x40, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
289+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x23, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
290+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x24, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
291+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x25, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
292+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x5E, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
293+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x26, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
294+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x2A, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
295+
0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
296+
0x37, 0x28, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
297+
0x37, 0x29, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
298+
0x37, 0x2D, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
299+
0x37, 0x3D, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
300+
0x37, 0x5B, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
301+
0x37, 0x5D, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
302+
0x37, 0x3B, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
303+
0x37, 0x27, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x2E, 0x2E, 0x2E, 0x45, 0x4E, 0x44, 0x18,
304+
0x18, 0x18, 0xCC, 0xBB, 0xAA, 0xDD, 0xCC, 0x05, 0x00, 0x0E, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69,
305+
0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x8A, 0xFF, 0xFF, 0x33, 0x33, 0x8F, 0x41, 0xAB,
306+
0x00, 0x00, 0x01, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x31, 0x40, 0x18
308307
};
309308

310309
static const uint8_t Encoding1_DataMacro [] =
@@ -322,6 +321,7 @@ static const uint8_t Encoding1_DataMacro [] =
322321
nlWeaveTLV_PATH(nlWeaveTLV_TAG_ANONYMOUS),
323322
nlWeaveTLV_NULL(nlWeaveTLV_TAG_FULLY_QUALIFIED_6Bytes(TestProfile_1, 17)),
324323
nlWeaveTLV_NULL(nlWeaveTLV_TAG_IMPLICIT_PROFILE_4Bytes(900000)),
324+
nlWeaveTLV_NULL(nlWeaveTLV_TAG_ANONYMOUS),
325325
nlWeaveTLV_STRUCTURE(nlWeaveTLV_TAG_IMPLICIT_PROFILE_4Bytes(4000000000ULL)),
326326
nlWeaveTLV_UTF8_STRING_2ByteLength(nlWeaveTLV_TAG_COMMON_PROFILE_4Bytes(70000), sizeof(sLargeString) - 1,
327327
'S', 'T', 'A', 'R', 'T', '.', '.', '.',
@@ -408,6 +408,9 @@ void WriteEncoding1(nlTestSuite *inSuite, TLVWriter& writer)
408408
err = writer5.PutNull(ProfileTag(TestProfile_2, 900000));
409409
NL_TEST_ASSERT(inSuite, err == WEAVE_NO_ERROR);
410410

411+
err = writer5.PutNull(AnonymousTag);
412+
NL_TEST_ASSERT(inSuite, err == WEAVE_NO_ERROR);
413+
411414
{
412415
TLVType outerContainerType;
413416

@@ -549,6 +552,10 @@ void ReadEncoding1(nlTestSuite *inSuite, TLVReader& reader)
549552

550553
TestNext<TLVReader>(inSuite, reader5);
551554

555+
TestNull(inSuite, reader5, AnonymousTag);
556+
557+
TestNext<TLVReader>(inSuite, reader5);
558+
552559
{
553560
TLVType outerContainerType;
554561

@@ -1539,7 +1546,7 @@ void CheckWeaveTLVUtilities(nlTestSuite *inSuite, void *inContext)
15391546

15401547
// Count
15411548
size_t count;
1542-
const size_t expectedCount = 17;
1549+
const size_t expectedCount = 18;
15431550
reader1.Init(reader);
15441551
reader1.Next();
15451552

@@ -2911,6 +2918,10 @@ void TestWeaveTLVReaderDup(nlTestSuite *inSuite)
29112918

29122919
TestNext<TLVReader>(inSuite, reader5);
29132920

2921+
TestNull(inSuite, reader5, AnonymousTag);
2922+
2923+
TestNext<TLVReader>(inSuite, reader5);
2924+
29142925
{
29152926
TLVType outerContainerType;
29162927

@@ -3601,6 +3612,9 @@ static WEAVE_ERROR ReadFuzzedEncoding1(nlTestSuite *inSuite, TLVReader& reader)
36013612
err = reader.Next(kTLVType_Null, ProfileTag(TestProfile_2, 900000));
36023613
SuccessOrExit(err);
36033614

3615+
err = reader.Next(kTLVType_Null, AnonymousTag);
3616+
SuccessOrExit(err);
3617+
36043618
err = reader.Next(kTLVType_Structure, ProfileTag(TestProfile_2, 4000000000ULL));
36053619
SuccessOrExit(err);
36063620

0 commit comments

Comments
 (0)