Skip to content

Commit c3f533e

Browse files
committed
chore: restructure the txt parse loop and reword the remaining echoes from the twelfth audit
1 parent 07e3812 commit c3f533e

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎src/zeroconf/_cache.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def async_add_records(self, entries: Iterable[DNSRecord]) -> bool:
7777
return new
7878

7979
def async_all_by_details(self, name: _str, type_: _int, class_: _int) -> list[DNSRecord]:
80-
"""Gets all matching entries by details.
80+
"""Return every cached record carrying this name, type and class.
8181
8282
This function is not thread-safe and must be called from
8383
the event loop.

‎src/zeroconf/_handlers/query_handler.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ def async_response( # pylint: disable=unused-argument
247247
continue
248248
if ucast_source:
249249
query_res.add_ucast_question_response(answer_set)
250-
# We always multicast as well even if its a unicast
251-
# source as long as we haven't done it recently (75% of ttl)
250+
# The answer also goes out by multicast even for a unicast
251+
# source; a copy multicast within the last second is folded
252+
# into the aggregated response instead (RFC 6762 section 14)
252253
query_res.add_mcast_question_response(answer_set)
253254

254255
return query_res.answers()

‎src/zeroconf/_services/info.pxd‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ cdef class ServiceInfo(RecordUpdateListener):
9090

9191
@cython.locals(
9292
length="unsigned char",
93-
index="unsigned int",
93+
pos="unsigned int",
94+
start="unsigned int",
95+
total="unsigned int",
9496
key_value=bytes,
9597
key=bytes,
9698
sep=bytes,

‎src/zeroconf/_services/info.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,26 +1044,26 @@ def _set_text(self, text: bytes) -> None:
10441044
def _unpack_text_into_properties(self) -> None:
10451045
"""Unpacks the text field into properties"""
10461046
text = self.text
1047-
end = len(text)
1048-
if end == 0:
1047+
total = len(text)
1048+
if total == 0:
10491049
# Properties should be set atomically
10501050
# in case another thread is reading them
10511051
self._properties = {}
10521052
return
10531053

1054-
index = 0
10551054
properties: dict[bytes, bytes | None] = {}
1056-
while index < end:
1057-
length = text[index]
1058-
index += 1
1059-
key_value = text[index : index + length]
1055+
pos = 0
1056+
while pos < total:
1057+
length = text[pos]
1058+
start = pos + 1
1059+
key_value = text[start : start + length]
1060+
pos = start + length
10601061
key, sep, value = key_value.partition(b"=")
10611062
if key not in properties:
10621063
# RFC 6763 section 6.4 distinguishes a key with no '=' (a
10631064
# boolean attribute: present, no value) from `key=` (present
10641065
# with an empty value), so test the separator, not the value.
10651066
properties[key] = value if sep else None
1066-
index += length
10671067

10681068
self._properties = properties
10691069

0 commit comments

Comments
 (0)