diff --git a/DnsServerCore/Dns/DnsServer.cs b/DnsServerCore/Dns/DnsServer.cs index baf8b0f4..0c10f1f4 100644 --- a/DnsServerCore/Dns/DnsServer.cs +++ b/DnsServerCore/Dns/DnsServer.cs @@ -926,6 +926,11 @@ namespace DnsServerCore.Dns return await ProcessRecursiveQueryAsync(request, null, null, !inAllowedZone, false); } } + catch (InvalidDomainNameException) + { + //format error response + return new DnsDatagram(request.Identifier, true, request.OPCODE, false, false, request.RecursionDesired, IsRecursionAllowed(remoteEP), false, false, DnsResponseCode.FormatError, request.Question); + } catch (Exception ex) { LogManager log = _log; @@ -1087,6 +1092,9 @@ namespace DnsServerCore.Dns } } + if (response.RecursionAvailable != isRecursionAllowed) + response = new DnsDatagram(response.Identifier, response.IsResponse, response.OPCODE, response.AuthoritativeAnswer, response.Truncation, response.RecursionDesired, isRecursionAllowed, response.AuthenticData, response.CheckingDisabled, response.RCODE, response.Question, response.Answer, response.Authority, response.Additional); + return Task.FromResult(response); }