Skip to content

Commit b6a52ce

Browse files
author
BiffoBear
committed
Rewrote the domain name parser code to properly account for pointers to labels.
1 parent 9f180d5 commit b6a52ce

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_dns.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,24 @@ class IN answer.
143143
# pylint: disable=too-many-nested-blocks
144144
try:
145145
for answer in range(answer_count):
146+
# Move the pointer past the name.
146147
label_length = response[pointer]
147-
if label_length >= 0xC0:
148-
# Pointer to the domain name, skip over it.
149-
pointer += 2
150-
else:
151-
# Domain name, skip through it.
152-
while label_length != 0x00: # Null represents root of domain name
148+
while True:
149+
if label_length >= 0xC0:
150+
# Pointer to a section of domain name, skip over it.
151+
pointer += 2
152+
label_length = response[pointer]
153+
if label_length == 0:
154+
# One byte past the end of the name.
155+
break
156+
else:
157+
# Section of the domain name, skip through it.
153158
pointer += label_length
154159
label_length = response[pointer]
160+
if label_length == 0:
161+
# On the null byte at the end of the name. Increment the pointer.
162+
pointer += 1
163+
break
155164
# Check for a type A answer.
156165
if int.from_bytes(response[pointer : pointer + 2], "big") == TYPE_A:
157166
# Check for an IN class answer.

0 commit comments

Comments
 (0)