Skip to content

Commit e579fad

Browse files
committed
Test we skip NSEC record with invalid name compression
1 parent 08e34a7 commit e579fad

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

tests/test_protocol.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,3 +959,31 @@ def test_dns_compression_loop_attack():
959959
)
960960
parsed = r.DNSIncoming(packet)
961961
assert len(parsed.answers) == 0
962+
963+
964+
def test_txt_after_invalid_nsec_name_still_usable():
965+
"""Test that we can see the txt record after the invalid nsec record."""
966+
packet = (
967+
b'\x00\x00\x84\x00\x00\x00\x00\x06\x00\x00\x00\x00\x06_sonos\x04_tcp\x05loc'
968+
b'al\x00\x00\x0c\x00\x01\x00\x00\x11\x94\x00\x15\x12Sonos-542A1BC9220E'
969+
b'\xc0\x0c\x12Sonos-542A1BC9220E\xc0\x18\x00/\x80\x01\x00\x00\x00x\x00'
970+
b'\x08\xc1t\x00\x04@\x00\x00\x08\xc0)\x00/\x80\x01\x00\x00\x11\x94\x00'
971+
b'\t\xc0)\x00\x05\x00\x00\x80\x00@\xc0)\x00!\x80\x01\x00\x00\x00x'
972+
b'\x00\x08\x00\x00\x00\x00\x05\xa3\xc0>\xc0>\x00\x01\x80\x01\x00\x00\x00x'
973+
b'\x00\x04\xc0\xa8\x02:\xc0)\x00\x10\x80\x01\x00\x00\x11\x94\x01*2info=/api'
974+
b'/v1/players/RINCON_542A1BC9220E01400/info\x06vers=3\x10protovers=1.24.1\nbo'
975+
b'otseq=11%hhid=Sonos_rYn9K9DLXJe0f3LP9747lbvFvh;mhhid=Sonos_rYn9K9DLXJe0f3LP9'
976+
b'747lbvFvh.Q45RuMaeC07rfXh7OJGm<location=http://192.168.2.58:1400/xml/device_'
977+
b'description.xml\x0csslport=1443\x0ehhsslport=1843\tvariant=2\x0emdnssequen'
978+
b'ce=0'
979+
)
980+
parsed = r.DNSIncoming(packet)
981+
# The NSEC record with the invalid name compression should be skipped
982+
assert parsed.answers[4].text == (
983+
b'2info=/api/v1/players/RINCON_542A1BC9220E01400/info\x06vers=3\x10protovers'
984+
b'=1.24.1\nbootseq=11%hhid=Sonos_rYn9K9DLXJe0f3LP9747lbvFvh;mhhid=Sonos_rYn'
985+
b'9K9DLXJe0f3LP9747lbvFvh.Q45RuMaeC07rfXh7OJGm<location=http://192.168.2.58:14'
986+
b'00/xml/device_description.xml\x0csslport=1443\x0ehhsslport=1843\tvarian'
987+
b't=2\x0emdnssequence=0'
988+
)
989+
assert len(parsed.answers) == 5

zeroconf/_protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def read_bitmap(self, end: int) -> List[int]:
262262
return rdtypes
263263

264264
def read_name(self) -> str:
265-
"""Reads a domain name from the packet"""
265+
"""Reads a domain name from the packet."""
266266
labels: List[str] = []
267267
self.seen_pointers.clear()
268268
self.offset = self._decode_labels_at_offset(self.offset, labels)
@@ -286,7 +286,7 @@ def _decode_labels_at_offset(self, off: int, labels: List[str]) -> int:
286286
continue
287287

288288
if length < 0xC0:
289-
raise IncomingDecodeError(f"DNS compression type {length} is unknown")
289+
raise IncomingDecodeError(f"DNS compression type {length} is unknown at {off}")
290290

291291
# We have a DNS compression pointer
292292
link = (length & 0x3F) * 256 + self.data[off + 1]

0 commit comments

Comments
 (0)