Skip to content

Commit

Permalink
Fix off-by-one in look checks for QName iterators. (#33273)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored May 2, 2024
1 parent 74c95db commit e0f9ede
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/core/QName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool SerializedQNameIterator::Next(bool followIndirectPointers)
}

size_t offset = static_cast<size_t>(((*mCurrentPosition & 0x3F) << 8) | *(mCurrentPosition + 1));
if (offset > mLookBehindMax)
if (offset >= mLookBehindMax)
{
// Potential infinite recursion.
mIsValid = false;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ TEST(TestQName, InvalidReferencing)

{
// Infinite recursion
static const uint8_t kData[] = "\03test\xc0\x00";
static const uint8_t kData[] = "\04test\xc0\x00";
SerializedQNameIterator it = AsSerializedQName(kData);

EXPECT_TRUE(it.Next());
Expand All @@ -145,7 +145,7 @@ TEST(TestQName, InvalidReferencing)

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

EXPECT_TRUE(it.Next());
Expand All @@ -164,7 +164,7 @@ TEST(TestQName, InvalidReferencing)

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

EXPECT_TRUE(it.Next());
Expand Down

0 comments on commit e0f9ede

Please sign in to comment.