DomainTree: throwing InvalidDomainNameException instead of DnsServerException to allow returning format error response.

This commit is contained in:
Shreyas Zare
2020-12-12 16:40:54 +05:30
parent 849df07c73
commit d18a480dd2
2 changed files with 53 additions and 7 deletions

View File

@@ -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;
}

View 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
}
}