Sming icon indicating copy to clipboard operation
Sming copied to clipboard

Refactor DnsServer

Open mikee47 opened this issue 3 days ago • 0 comments

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.

Tested using nslookup with santizers active.

mikee47 avatar Jun 29 '24 15:06 mikee47