From d18bf2ab7775b437010197acafa7eb1e6a022dc0 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 20 Jun 2020 19:22:45 +0530 Subject: [PATCH] ZoneTree: added IsKeySubDomain() checks in FindNodeValue() instead of checking it afterwards for correctness. --- DnsServerCore/Dns/Zones/ZoneTree.cs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/DnsServerCore/Dns/Zones/ZoneTree.cs b/DnsServerCore/Dns/Zones/ZoneTree.cs index 37ee3ec6..f042efd4 100644 --- a/DnsServerCore/Dns/Zones/ZoneTree.cs +++ b/DnsServerCore/Dns/Zones/ZoneTree.cs @@ -418,19 +418,28 @@ namespace DnsServerCore.Dns.Zones { if ((zoneValue is PrimaryZone) || (zoneValue is SecondaryZone) || (zoneValue is StubZone) || (zoneValue is ForwarderZone)) { - //hosted primary/secondary/stub/forwarder zone found - closestDelegation = null; - closestAuthority = value; + if (IsKeySubDomain(value.Key, key)) + { + //hosted primary/secondary/stub/forwarder zone found + closestDelegation = null; + closestAuthority = value; + } } else if ((zoneValue is SubDomainZone) && (closestDelegation == null) && zoneValue.ContainsNameServerRecords()) { - //delegated sub domain found - closestDelegation = value; + if (IsKeySubDomain(value.Key, key)) + { + //delegated sub domain found + closestDelegation = value; + } } } else if ((zoneValue is CacheZone) && zoneValue.ContainsNameServerRecords()) { - closestDelegation = value; + if (IsKeySubDomain(value.Key, key)) + { + closestDelegation = value; + } } } } @@ -674,12 +683,12 @@ namespace DnsServerCore.Dns.Zones if (nodeValue == null) { //zone not found - if ((closestDelegation != null) && IsKeySubDomain(closestDelegation.Key, key)) + if (closestDelegation != null) delegation = closestDelegation.Value; else delegation = null; - if ((closestAuthority != null) && IsKeySubDomain(closestAuthority.Key, key)) + if (closestAuthority != null) authority = closestAuthority.Value; else authority = null; @@ -709,14 +718,14 @@ namespace DnsServerCore.Dns.Zones delegation = zoneValue; else if ((zoneValue is CacheZone) && zoneValue.ContainsNameServerRecords()) delegation = zoneValue; - else if ((closestDelegation != null) && IsKeySubDomain(closestDelegation.Key, key)) + else if (closestDelegation != null) delegation = closestDelegation.Value; else delegation = null; if ((zoneValue is PrimaryZone) || (zoneValue is SecondaryZone) || (zoneValue is StubZone) || (zoneValue is ForwarderZone)) authority = zoneValue; - else if ((closestAuthority != null) && IsKeySubDomain(closestAuthority.Key, key)) + else if (closestAuthority != null) authority = closestAuthority.Value; else authority = null;