mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
DomainTree: throwing InvalidDomainNameException instead of DnsServerException to allow returning format error response.
This commit is contained in:
@@ -97,7 +97,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
return Array.Empty<byte>();
|
||||
|
||||
if (domain.Length > 255)
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: length cannot exceed 255 bytes.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: length cannot exceed 255 bytes.");
|
||||
|
||||
byte[] key = new byte[domain.Length + 1];
|
||||
int keyOffset = 0;
|
||||
@@ -117,16 +117,16 @@ namespace DnsServerCore.Dns.Zones
|
||||
labelLength = labelEnd - labelStart;
|
||||
|
||||
if (labelLength == 0)
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: label length cannot be 0 byte.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot be 0 byte.");
|
||||
|
||||
if (labelLength > 63)
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: label length cannot exceed 63 bytes.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label length cannot exceed 63 bytes.");
|
||||
|
||||
if (domain[labelStart + 1] == '-')
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: label cannot start with hyphen.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label cannot start with hyphen.");
|
||||
|
||||
if (domain[labelEnd] == '-')
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: label cannot end with hyphen.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: label cannot end with hyphen.");
|
||||
|
||||
if ((labelLength == 1) && (domain[labelStart + 1] == '*'))
|
||||
{
|
||||
@@ -138,11 +138,11 @@ namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
labelChar = domain[i];
|
||||
if (labelChar >= _keyMap.Length)
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");
|
||||
|
||||
labelKeyCode = _keyMap[labelChar];
|
||||
if (labelKeyCode == 0xff)
|
||||
throw new DnsServerException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");
|
||||
throw new InvalidDomainNameException("Invalid domain name [" + domain + "]: invalid character [" + labelChar + "] was found.");
|
||||
|
||||
key[keyOffset++] = labelKeyCode;
|
||||
}
|
||||
|
||||
46
DnsServerCore/Dns/Zones/InvalidDomainNameException.cs
Normal file
46
DnsServerCore/Dns/Zones/InvalidDomainNameException.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
public class InvalidDomainNameException : DnsServerException
|
||||
{
|
||||
#region constructors
|
||||
|
||||
public InvalidDomainNameException()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public InvalidDomainNameException(string message)
|
||||
: base(message)
|
||||
{ }
|
||||
|
||||
public InvalidDomainNameException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{ }
|
||||
|
||||
protected InvalidDomainNameException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
|
||||
: base(info, context)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user