diff options
author | Adam <Adam@anope.org> | 2010-10-09 20:02:19 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-10-09 20:02:19 -0400 |
commit | 0ac77d0e42952765d2899565427ce92679142c17 (patch) | |
tree | 6e8673b5c8d78418fb4f27e51ba5c2b30bb3cc94 /src/dns.cpp | |
parent | 5ca2df1edb1d1a053a82cc3ec11e1307c02c401c (diff) |
Fixed a crash in the dns engine if we receive a reply after a request has timedout
Diffstat (limited to 'src/dns.cpp')
-rw-r--r-- | src/dns.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/dns.cpp b/src/dns.cpp index b3f97caed..2c586b02e 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -38,9 +38,11 @@ DNSRequest::DNSRequest(const Anope::string &addr, QueryType qt, bool cache, Modu return; } - while (DNSEngine->requests.count((p->id = GetRandomID()))); + short packet_id; + while (DNSEngine->requests.count((packet_id = GetRandomID()))); - DNSEngine->requests[p->id] = this; + p->id = this->id = packet_id; + DNSEngine->requests[this->id] = this; DNSEngine->packets.push_back(p); SocketEngine->MarkWritable(DNSEngine->sock); @@ -50,10 +52,17 @@ DNSRequest::DNSRequest(const Anope::string &addr, QueryType qt, bool cache, Modu DNSRequest::~DNSRequest() { + /* DNSRequest came back, delete the timeout */ if (!this->timeout->done) { delete this->timeout; } + /* Timeout timed us out, delete us from the requests map */ + else + { + /* We can leave the packet, if it comes back later we will drop it */ + DNSEngine->requests.erase(this->id); + } } void DNSRequest::OnError(DNSError error, const Anope::string &message) @@ -208,6 +217,9 @@ DNSSocket::DNSSocket() : ConnectionSocket(false, SOCK_DGRAM) DNSSocket::~DNSSocket() { + for (unsigned i = DNSEngine->packets.size(); i > 0; --i) + delete DNSEngine->packets[i - 1]; + DNSEngine->packets.clear(); Log() << "Resolver: Lost connection to nameserver"; DNSEngine->sock = NULL; } @@ -458,17 +470,14 @@ bool DNSSocket::ProcessWrite() Log(LOG_DEBUG_2) << "Resolver: Writing to UDP socket"; bool cont = true; - for (unsigned i = DNSEngine->packets.size(); i > 0; --i) + for (unsigned i = DNSEngine->packets.size(); cont && i > 0; --i) { DNSPacket *r = DNSEngine->packets[i - 1]; unsigned char buffer[524]; r->FillBuffer(buffer); - cont = this->SendTo(buffer, r->payload_count + 12) >= 0; - - if (!cont) - break; + cont = this->SendTo(buffer, r->payload_count + 12) == r->payload_count + 12; delete r; DNSEngine->packets.erase(DNSEngine->packets.begin() + i - 1); |