summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-03 13:46:42 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-03 13:46:42 +0000
commitbcc3c8566cc5fcff6c39c94ac823941ad1e60b83 (patch)
treee496df6f73474c20fba6f1c56b4a86337474f787 /src
parent30911b2ae8c8d8bdf741fc642f49956b8c9b98c0 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/dns.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index 993da5381..648e8f4a4 100644
--- a/src/dns.cpp
+++ b/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;