Fix infinite loop when all DNS request slots are in use

This is not the best way to detect this scenario, a better detection mechanism will replace this in the future
This commit is contained in:
attilamolnar 2013-03-20 23:43:51 +01:00
parent fd6a8e9392
commit 21f7e4a8cd

View File

@ -258,8 +258,28 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id, const char* original)
return NULL;
/* Create an id */
unsigned int tries = 0;
do {
id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
if (++tries == DNS::MAX_REQUEST_ID*5)
{
// If we couldn't find an empty slot this many times, do a sequential scan as a last
// resort. If an empty slot is found that way, go on, otherwise throw an exception
id = -1;
for (int i = 0; i < DNS::MAX_REQUEST_ID; i++)
{
if (!requests[i])
{
id = i;
break;
}
}
if (id == -1)
throw ModuleException("DNS: All ids are in use");
break;
}
} while (requests[id]);
DNSRequest* req = new DNSRequest(this, id, original);