TechnitiumSoftware/DnsServer · error · InvalidDomainNameException
Invalid domain name [{domain}]: label length cannot be 0 byt
Error message
Invalid domain name [{domain}]: label length cannot be 0 byte. What it means
Thrown by DomainTree.ConvertToByteKey when a label within the domain name has zero length — i.e. two consecutive dots, a leading dot, or a trailing dot that resolves to an empty label. DNS labels must be 1–63 octets (RFC 1035), so an empty label is illegal outside the root. Only thrown when throwException is true.
Source
Thrown at DnsServerCore/Dns/Trees/DomainTree.cs:141
int labelStart;
int labelEnd = domain.Length - 1;
int labelLength;
int labelChar;
byte labelKeyCode;
int i;
do
{
if (labelEnd < 0)
labelEnd = 0;
labelStart = domain.LastIndexOf('.', labelEnd);
labelLength = labelEnd - labelStart;
if (labelLength == 0)
{
if (throwException)
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot be 0 byte.");
return null;
}
if (labelLength > 63)
{
if (throwException)
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot exceed 63 bytes.");
return null;
}
if ((labelLength == 1) && (domain[labelStart + 1] == '*')) //[*]
{
key[keyOffset++] = 1;
}
else
{View on GitHub (pinned to d0484b6c1e)
Solutions
- Normalize the domain before use: strip a single trailing root dot, reject consecutive dots, and trim leading dots.
- Validate with a regex or a dedicated normalization routine prior to tree operations.
- Use ConvertToByteKey(domain, throwException: false) for probing so an invalid name yields null.
Example fix
// before
_tree.GetOrAdd("example..com", value);
// after
string norm = domain.TrimEnd('.').Replace("..", ".");
if (string.IsNullOrEmpty(norm) || norm.Contains("..") || norm.StartsWith("."))
return;
_tree.GetOrAdd(norm, value); Defensive patterns
Strategy: validation
Validate before calling
string NormalizeDomain(string d)
{
if (d is null) return null;
d = d.TrimEnd('.');
if (d.Contains("..") || d.StartsWith(".") || d.EndsWith(".")) return null;
return d;
} Type guard
static bool HasNoEmptyLabels(string d) =>
!d.StartsWith(".") && !d.Contains("..") && (!d.EndsWith(".") || d.Length == 1); Prevention
- Normalize user input: trim a single trailing root dot, reject consecutive/leading dots.
- Validate zone/record names at the API boundary.
- Probe with throwException=false for invalid-name detection without exceptions.
When it happens
Trigger: Passing a domain containing '..', '.', a leading '.', or a trailing '.' (after LastIndexOf('.') resolution yields labelLength == 0) to a DomainTree-derived tree operation with throwException=true.
Common situations: User-entered zone/record names not normalized (e.g. 'example..com', '.example.com', 'example.com.'), malformed zone file import, or string concatenation producing empty labels.
Related errors
- Invalid domain name [{domain}]: length cannot exceed 255 byt
- Invalid domain name [{domain}]: label length cannot exceed 6
- Invalid domain name [{domain}]: invalid character [{labelCha
- Zone does not contain SOA record.
- Failed to load DNS zone file: the zone file does not contain
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/c7482ecf4c69c7a5.
Report an issue: GitHub.