]> granicus.if.org Git - pdns/commitdiff
re enable validDNSName check
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 15 Jun 2016 09:34:35 +0000 (11:34 +0200)
committermind04 <mind04@monshouwer.org>
Wed, 15 Jun 2016 09:58:34 +0000 (11:58 +0200)
pdns/packethandler.cc

index 5202c21d114b2a4000784e045cad0f758b49b56f..e35e4be14a41761a08816212043423b01d505408 100644 (file)
@@ -881,6 +881,24 @@ int PacketHandler::processNotify(DNSPacket *p)
   return 0;
 }
 
+bool validDNSName(const DNSName &name)
+{
+  string::size_type pos, length;
+  char c;
+  for(const auto& s : name.getRawLabels()) {
+    length=s.length();
+    for(pos=0; pos < length; ++pos) {
+      c=s[pos];
+      if(!((c >= 'a' && c <= 'z') ||
+           (c >= 'A' && c <= 'Z') ||
+           (c >= '0' && c <= '9') ||
+           c =='-' || c == '_' || c=='*' || c=='.' || c=='/' || c=='@' || c==' ' || c=='\\' || c==':'))
+        return false;
+    }
+  }
+  return true;
+}
+
 DNSPacket *PacketHandler::question(DNSPacket *p)
 {
   DNSPacket *ret;
@@ -1158,15 +1176,15 @@ DNSPacket *PacketHandler::questionOrRecurse(DNSPacket *p, bool *shouldRecurse)
 
     // XXX FIXME do this in DNSPacket::parse ?
 
-    // if(!validDNSName(p->qdomain)) {
-    //   if(d_logDNSDetails)
-    //     L<<Logger::Error<<"Received a malformed qdomain from "<<p->getRemote()<<", '"<<p->qdomain<<"': sending servfail"<<endl;
-    //   S.inc("corrupt-packets");
-    //   S.ringAccount("remotes-corrupt", p->d_remote);
-    //   S.inc("servfail-packets");
-    //   r->setRcode(RCode::ServFail);
-    //   return r;
-    // }
+    if(!validDNSName(p->qdomain)) {
+      if(d_logDNSDetails)
+        L<<Logger::Error<<"Received a malformed qdomain from "<<p->getRemote()<<", '"<<p->qdomain<<"': sending servfail"<<endl;
+      S.inc("corrupt-packets");
+      S.ringAccount("remotes-corrupt", p->d_remote);
+      S.inc("servfail-packets");
+      r->setRcode(RCode::ServFail);
+      return r;
+    }
     if(p->d.opcode) { // non-zero opcode (again thanks RA!)
       if(p->d.opcode==Opcode::Update) {
         S.inc("dnsupdate-queries");