alexreinert/ARSoft.Tools.Net

Exception has found after migration.

Closed this issue · 4 comments

pil78 commented

Hi,
during usage of you library sometimes we track the exception:
System.Exception: Error parsing dns query ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') at System.ArraySegment1.System.Collections.Generic.IList.get_Item(Int32 index)
at ARSoft.Tools.Net.Dns.DnsMessageBase.ParseDomainName(IList1 resultData, Int32 currentPosition, Int32& uncompressedLabelBytes) at ARSoft.Tools.Net.Dns.DnsQuestion.Parse(IList1 data, Int32& currentPosition)
at ARSoft.Tools.Net.Dns.DnsMessageBase.ParseQuestionSection(IList1 data, Int32& currentPosition, Int32 recordCount) at ARSoft.Tools.Net.Dns.DnsMessageBase.ParseInternal(IList1 data, SelectTsigKey tsigKeySelector, Byte[] originalMac)
at ARSoft.Tools.Net.Dns.DnsMessageBase.CreateByFlag(IList1 package, SelectTsigKey tsigKeySelector, Byte[] originalMac) at ARSoft.Tools.Net.Dns.DnsServer.ProcessRawPackageAsync(IServerConnection connection, DnsReceivedRawPackage queryPackage, CancellationToken token) --- End of inner exception stack trace --- at ARSoft.Tools.Net.Dns.DnsServer.ProcessRawPackageAsync(IServerConnection connection, DnsReceivedRawPackage queryPackage, CancellationToken token)

Our dev-ops engineer managed to reproduce this with small powershell sceipt:
`function Send-UdpDatagram
{
Param ([string] $EndPoint,
[int] $Port,
[string] $Message)

  $IP = [System.Net.Dns]::GetHostAddresses($EndPoint) 
  $Address = [System.Net.IPAddress]::Parse($IP) 
  $EndPoints = New-Object System.Net.IPEndPoint($Address, $Port) 
  $Socket = New-Object System.Net.Sockets.UDPClient 
  $EncodedText = [Text.Encoding]::ASCII.GetBytes($Message) 
  $SendMessage = $Socket.Send($EncodedText, 12, $EndPoints)
  $Socket.Close() 

}

While ($True){
Write-Host "Send Message"
Send-UdpDatagram -EndPoint "127.0.0.1" -Port 53 -Message "F/*/**966jgFF"
}`
Could you please check this and fix, because I have no ways to override or implement this by myself.

pil78 commented

PS: This has started after migration our application from 2.x.x to 3.x.x version. (We changed our code from old .net framework to .net 6)

The data you provided contains a malformed DNS message, so what should happen with that.
In my tests this will not crash the server, only the ExceptionThrown event is fired and it is up to you, to handle the situation. One solution would be to just ignore that exception in the EventHandler.

pil78 commented

Thanks for answering.
Yep, I handled the error and ignoring - what I did for now.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.