zhouhan0126/DNSServer---esp32

Crash in combination with ESPAsyncWebserver / Buffer overrun

Opened this issue · 0 comments

trlink commented

Hi all,

I ran into a problem using the DNSServer in combination with the ESPAsyncWebserver:

If I open a web site, when connected to the ESP-AP the server does not respond (in fact it gets no IP). I found the cause in the following function:

`String DNSServer::getDomainNameWithoutWwwPrefix()
{
// Error checking : if the buffer containing the DNS request is a null pointer, return an empty domain
String parsedDomainName = "";
if (_buffer == NULL)
return parsedDomainName;

// Set the start of the domain just after the header (12 bytes). If equal to null character, return an empty domain
unsigned char *start = _buffer + DNS_OFFSET_DOMAIN_NAME;
if (*start == 0)
{
return parsedDomainName;
}

int pos = 0;

while(pos < _currentPacketSize)
{
unsigned char labelLength = (start + pos);
for(int i = 0; i < labelLength; i++)
{
pos++;
parsedDomainName += (char)
(start + pos);
}
pos++;
if (*(start + pos) == 0)
{
downcaseAndRemoveWwwPrefix(parsedDomainName);
return parsedDomainName;
}
else
{
parsedDomainName += ".";
}
}

return parsedDomainName;
}`

Initially, the while-loop was while(true), which created the problem, that if the udp packet is not formed correctly, it runs into a buffer overrun...

I corrected it, hope that helps....