Skip to content

Commit e07a8af

Browse files
committed
fixed root domain parsing
1 parent d31aa69 commit e07a8af

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/dnsprotocol/utils.nim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ proc parseCharacterStrings*(css: var seq[string], ss: StringStream,
144144
proc parseDomainName*(name: var string, ss: StringStream) =
145145
## Parses a Domain Name contained in `ss` binary dns protocol message and
146146
## stores it in `name`.
147-
setLen(name, 254) # Seria 253, no entanto há o '.' adicionado ao final que é removido quando terminado.
147+
##
148+
## **Note**
149+
## - `name` will always have its last character as a '.', which is the root of
150+
## the domain name.
151+
setLen(name, 255)
148152

149153
var
150154
mainOffset = -1
@@ -163,6 +167,11 @@ proc parseDomainName*(name: var string, ss: StringStream) =
163167

164168
continue
165169
elif 0'u8 == length:
170+
if lenName == 0:
171+
name[lenName] = '.'
172+
173+
lenName = 1
174+
166175
break
167176
elif 63'u8 < length:
168177
raise newException(ValueError, "Not a legal name (label exceeds 63 octets)")

0 commit comments

Comments
 (0)