From 849df07c731660eddfba40fd899678905d094ddc Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 12 Dec 2020 16:40:06 +0530 Subject: [PATCH] DnsServer: returning format error response when domain name is invalid. Setting recursion available flag in response for auth zone when recursion is desired since dns clients like nslookup and dig complain about it otherwise. --- DnsServerCore/Dns/DnsServer.cs | 8 ++++++++ 1 file changed, 8 insertions(+) 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); }