]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_dns.cpp
core_hostname_lookup Don't adjust DnsBad stats
[user/henk/code/inspircd.git] / src / coremods / core_dns.cpp
index f4f85e2532f0bb6d54fd21ff25da084e8bbaecb3..829351f04dceec1cc07ee37786ced76aaf1b9a85 100644 (file)
@@ -33,6 +33,11 @@ using namespace DNS;
  */
 class Packet : public Query
 {
+       static bool IsValidName(const std::string& name)
+       {
+               return (name.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-") == std::string::npos);
+       }
+
        void PackName(unsigned char* output, unsigned short output_size, unsigned short& pos, const std::string& name)
        {
                if (pos + name.length() + 2 > output_size)
@@ -183,6 +188,9 @@ class Packet : public Query
                        case QUERY_PTR:
                        {
                                record.rdata = this->UnpackName(input, input_size, pos);
+                               if (!IsValidName(record.rdata))
+                                       throw Exception("Invalid name"); // XXX: Causes the request to time out
+
                                break;
                        }
                        default:
@@ -527,6 +535,13 @@ class MyManager : public Manager, public Timer, public EventHandler
                        return;
                }
 
+               if (static_cast<Question&>(*request) != recv_packet.question)
+               {
+                       // This can happen under high latency, drop it silently, do not fail the request
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received an answer that isn't for a question we asked");
+                       return;
+               }
+
                if (recv_packet.flags & QUERYFLAGS_OPCODE)
                {
                        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received a nonstandard query");