From bcc3c8566cc5fcff6c39c94ac823941ad1e60b83 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 3 Aug 2006 13:46:42 +0000 Subject: 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 --- src/dns.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') 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; -- cgit v1.2.3