DNSServer fix custom code replies (#7475)

custom code reply was sending garbage from a buffer instead of crafted DNS header
This commit is contained in:
vortigont 2022-12-15 00:06:44 +09:00 committed by GitHub
parent 5bc37a701b
commit 27e6f35f69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -175,8 +175,6 @@ String DNSServer::getDomainNameWithoutWwwPrefix()
void DNSServer::replyWithIP() void DNSServer::replyWithIP()
{ {
if (_buffer == NULL) return;
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort()); _udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
// Change the type of message to a response and set the number of answers equal to // Change the type of message to a response and set the number of answers equal to
@ -215,12 +213,11 @@ void DNSServer::replyWithIP()
void DNSServer::replyWithCustomCode() void DNSServer::replyWithCustomCode()
{ {
if (_buffer == NULL) return;
_dnsHeader->QR = DNS_QR_RESPONSE; _dnsHeader->QR = DNS_QR_RESPONSE;
_dnsHeader->RCode = (unsigned char)_errorReplyCode; _dnsHeader->RCode = (unsigned char)_errorReplyCode;
_dnsHeader->QDCount = 0; _dnsHeader->QDCount = 0;
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort()); _udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
_udp.write(_buffer, sizeof(DNSHeader)); _udp.write((unsigned char*)_dnsHeader, sizeof(DNSHeader));
_udp.endPacket(); _udp.endPacket();
} }