Skip to content

Commit cd7fd2c

Browse files
committed
Pull request project-chip#2094: [MATTER-4282] [Cherry-pick]Fix off-by-one in look checks for QName iterators. (project-chip#33273)
Merge in WMN_TOOLS/matter from cherry-pick/psirt_wifi to RC_2.3.1-1.3 Squashed commit of the following: commit 1556eac8f7bb54f90c7f550c61b5d438f0d2123c Author: Andrei Litvin <andy314@gmail.com> Date: Thu May 2 15:06:07 2024 -0400 Fix off-by-one in look checks for QName iterators. (project-chip#33273) Unit test sizes for the string `test` were off by one which masked a off-by-one comparison in QName handling. Update unit test and comparisons. This will disallow backward references to "self" for qnames. Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent 3c70244 commit cd7fd2c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/lib/dnssd/minimal_mdns/core/QName.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool SerializedQNameIterator::Next(bool followIndirectPointers)
6161
}
6262

6363
size_t offset = static_cast<size_t>(((*mCurrentPosition & 0x3F) << 8) | *(mCurrentPosition + 1));
64-
if (offset > mLookBehindMax)
64+
if (offset >= mLookBehindMax)
6565
{
6666
// Potential infinite recursion.
6767
mIsValid = false;

src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext)
136136

137137
{
138138
// Infinite recursion
139-
static const uint8_t kData[] = "\03test\xc0\x00";
139+
static const uint8_t kData[] = "\04test\xc0\x00";
140140
SerializedQNameIterator it = AsSerializedQName(kData);
141141

142142
NL_TEST_ASSERT(inSuite, it.Next());
@@ -146,7 +146,7 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext)
146146

147147
{
148148
// Infinite recursion by referencing own element (inside the stream)
149-
static const uint8_t kData[] = "\03test\xc0\x05";
149+
static const uint8_t kData[] = "\04test\xc0\x05";
150150
SerializedQNameIterator it = AsSerializedQName(kData);
151151

152152
NL_TEST_ASSERT(inSuite, it.Next());
@@ -165,7 +165,7 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext)
165165

166166
{
167167
// Reference that goes forwad instead of backward
168-
static const uint8_t kData[] = "\03test\xc0\x07";
168+
static const uint8_t kData[] = "\04test\xc0\x07";
169169
SerializedQNameIterator it = AsSerializedQName(kData);
170170

171171
NL_TEST_ASSERT(inSuite, it.Next());

0 commit comments

Comments
 (0)