mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 19:19:02 -04:00
Properly check for duplicate dns id's from the PRNG
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4667 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
30911b2ae8
commit
bcc3c8566c
14
src/dns.cpp
14
src/dns.cpp
@ -202,7 +202,13 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
|
||||
/* Add a query with a predefined header, and allocate an ID for it. */
|
||||
DNSRequest* DNS::AddQuery(DNSHeader *header, int &id)
|
||||
{
|
||||
id = DNS::PRNG() & 0xFFFF;
|
||||
id = this->PRNG() & 0xFFFF;
|
||||
|
||||
/* This id is already 'in flight', pick another.
|
||||
* -- Thanks jilles
|
||||
*/
|
||||
while (requests.find(id) != requests.end())
|
||||
id = this->PRNG() & 0xFFFF;
|
||||
|
||||
DNSRequest* req = new DNSRequest(this->myserver);
|
||||
|
||||
@ -215,8 +221,10 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id)
|
||||
header->nscount = 0;
|
||||
header->arcount = 0;
|
||||
|
||||
if (requests.find(id) == requests.end())
|
||||
requests[id] = req;
|
||||
/* At this point we already know the id doesnt exist,
|
||||
* so there needs to be no second check for the ::end()
|
||||
*/
|
||||
requests[id] = req;
|
||||
|
||||
/* According to the C++ spec, new never returns NULL. */
|
||||
return req;
|
||||
|
Loading…
x
Reference in New Issue
Block a user