Changeset 451

Show
Ignore:
Timestamp:
07/18/05 08:33:42 (9 years ago)
Author:
ahu
Message:

lots stricter DNS name validation - candidate for 2.9.18.1.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/packethandler.cc

    r420 r451  
    491491 
    492492 
     493 
     494bool validDNSName(const string &name) 
     495{ 
     496  string::size_type pos, length=name.length(); 
     497  char c; 
     498  for(pos=0; pos < length; ++pos) { 
     499    c=name[pos]; 
     500    if(!((c >= 'a' && c <= 'z') || 
     501         (c >= 'A' && c <= 'Z') || 
     502         (c >= '0' && c <= '9') || 
     503         c =='-' || c == '_' || c=='*' || c=='.')) 
     504      return false; 
     505  } 
     506  return true; 
     507 
     508 
    493509//! Called by the Distributor to ask a question. Returns 0 in case of an error 
    494510DNSPacket *PacketHandler::question(DNSPacket *p) 
     
    518534    // XXX FIXME do this in DNSPacket::parse ? 
    519535 
    520     if(!p->qdomain.empty() && p->qdomain.find_first_of("%|")!=string::npos) { 
     536    if(!validDNSName(p->qdomain)) { 
    521537      L<<Logger::Error<<"Received a malformed qdomain from "<<p->getRemote()<<", '"<<p->qdomain<<"': dropping"<<endl; 
    522538      S.inc("corrupt-packets");