mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 19:19:02 -04:00
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:
parent
fd6a8e9392
commit
21f7e4a8cd
20
src/dns.cpp
20
src/dns.cpp
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user