This PR is just a refactor of the DnsServer class as it's a bit more complex than necessary. No additional functionality added, but a few extra bounds checks have been added.
Move downcaseAndRemoveWwwPrefix, getDomainNameWithoutWwwPrefix and requestIncludesOnlyOneQuestion into private namespace (with appropriate parameter) - these do not need to be class members.
Remove dnsHeader and buffer, these are only used locally.
Move bulk of logic into separate processQuestion method.
Add additional debug output, printing content of question/response packets.
Fix potential issue with getDomainNameWithoutWwwPrefix if www. is contained within the domain name (unlikely, but possible)
Don't allocate response buffer on stack - size is potentially unbounded. Instead, re-use the allocated buffer for the response, simpler as our answer is just appended to the received question.
This PR is just a refactor of the
DnsServer
class as it's a bit more complex than necessary. No additional functionality added, but a few extra bounds checks have been added.Move
downcaseAndRemoveWwwPrefix
,getDomainNameWithoutWwwPrefix
andrequestIncludesOnlyOneQuestion
into private namespace (with appropriate parameter) - these do not need to be class members.Remove
dnsHeader
andbuffer
, these are only used locally.Move bulk of logic into separate
processQuestion
method.Add additional debug output, printing content of question/response packets.
Fix potential issue with
getDomainNameWithoutWwwPrefix
ifwww.
is contained within the domain name (unlikely, but possible)Don't allocate response buffer on stack - size is potentially unbounded. Instead, re-use the allocated buffer for the response, simpler as our answer is just appended to the received question.
Tested using nslookup with santizers active.